When a python script is supposed to be run from a pyenv
virtualenv
what is the correct shebang for the file?
As an example test case, the default python on my system (OSX) does not have pandas
installed. The pyenv virtualenv venv_name
does. I tried getting the path of the python executable from the virtualenv.
$ pyenv activate venv_name
(venv_name)$ which python
/Users/username/.pyenv/shims/python
So I made my example script.py
:
#!/Users/username/.pyenv/shims/python
import pandas as pd
print 'success'
But when I tried running the script, I got an error:
(venv_name) $ ./script.py
./script.py: line 2: import: command not found
./script.py: line 3: print: command not found
Although running that path on the command line works fine:
(venv_name) $ /Users/username/.pyenv/shims/python script.py
success
(venv_name) $ python script.py # also works
success
What is the proper shebang for this? Ideally, I want something generic so that it will point at the python of whatever my current venv is.
See Question&Answers more detail:os