1

Suppose you write a Python shell script. It will probably start with something like this:

#!/usr/bin/python

The problem is, if you often work with virtualenv this call is just plain wrong. You actually would like this script to call virtualenv's python binary, if it is in this environment and /usr/bin/python/ otherwise. Just like your shell would decide, when you write python as a shell command.

How would you write your #! line to fulfil this requirement?

2 Answers 2

6

Use #!/usr/bin/env python instead.

The env command looks up binaries in the current PATH; activating your virtual environment adds your virtualenv bin/ directory to the path and env will find your python binary there instead of the global python.

Sign up to request clarification or add additional context in comments.

Comments

0

try:

#!/usr/bin/env python

...

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.