1

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

6

Assuming the python source file is in a directory that is on your path do the following:

  1. Add this line to the top of your python file: #!/usr/bin/env python
  2. Set your python file to be executable: chmod +x test.2.py
  3. Run your python script with: test.2.py
Sign up to request clarification or add additional context in comments.

1 Comment

I'm inside a virtualenv. I have to call ./test.2.py
4

The 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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.