rbrtl rbrtl - 1 year ago 80
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

What am I doing wrong here?


# /usr/bin/env python

import sys

print sys.version_info

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download