rbrtl rbrtl - 1 month ago 7
Bash Question

Virtualenv not working with executable .py file

I was having a problem getting a python script to run in the shell:

$ chmod u+x scratch.py
$ ./scratch.py
./scratch.py: line 3: import: not found
sys.version_info
$


What am I doing wrong here?

scratch.py:

# /usr/bin/env python

import sys

print sys.version_info

Answer

You're missing the shebang's ! at the top of your script, so the shell is not recognizing your script as a Python script:

#!/usr/bin/env python
 ^
Comments