Why does using / usr / bin / env violate my Python import?

Python 2.7.3 on OSX 10.8.2

I am currently writing a script that imports a markdown module. I used #!/usr/bin/env pythonshebang for portability. The script works fine when I run it directly in the shell via./myscript.py arg1

When I run a script due to a shell (login), for example, through AppleScript do shell script "/path/to/myscript.py " & quoted form of arg1, it does not work with

myscript.py", line 8, in <module>
    import markdown
ImportError: No module named markdown

I assume this might be a problem for shebang, so I changed the shebang to my python location #!/usr/local/bin/pythonand of course the script worked fine.

So my question is twofold:

  • Why /usr/bin/env pythondoes use interrupt my import?
  • How can I avoid this problem without using /usr/local/bin/python?
+5
2

#!/usr/bin/env python "go find python on $PATH, ". , , , , .

, /usr/local/bin/python /usr/bin/env python . type -a python, python $PATH. type -a python :

python is /opt/local/bin/python
python is /usr/bin/python
python is /usr/local/bin/python

( MacPorts.)

, , , , $PATH, . , /usr/bin/env .

+3

, , PATH AppleScript.

, .profile :

PATH=/usr/local/bin:$PATH

, , . , , Python /usr/bin/python, markdown.

+1

All Articles