I would like to add some python script to path.
I can add bash scripts to folders in my path and then execute them from everywhere. When I do so with python script, I can only execute them when I am in the same directory.
Per exemple, if I put test and test2.py in the same folder in my path.
This work:
sh test success hello world
This doesn't:
python test.2.py python: can't open file 'test2.py': [Errno 2] No such file or directory [Errno 2] No such file or directory
2 Answers 2
Assuming the python source file is in a directory that is on your path do the following:
- Add this line to the top of your python file:
#!/usr/bin/env python - Set your python file to be executable:
chmod +x test.2.py - Run your python script with:
test.2.py
answered Feb 2, 2013 at 7:59
Matt
3,7393 gold badges19 silver badges35 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Stefan_EOX
I'm inside a virtualenv. I have to call
./test.2.pyThe python command doesn't search $PATH for scripts, like bash does.
Make test.2.py executable, and make the first line:
#!/usr/bin/python
Then run it by typing:
test.2.py
answered Feb 2, 2013 at 7:58
Barmar
789k57 gold badges555 silver badges669 bronze badges
Comments
default