monkinetic weblog

Steve Ivy's Weblog - Since 1999 - XII Ed.

Mac OS X Ignoring Python Shebang?!

I've recently added a second Python install on my OS X box, in /opt/Python. I've got a script with a shebang at the top:

#!/opt/Python/bin/python

When I run the script like so:

/opt/Python/bin/python alltests.py

It runs fine. If I just:

./alltests.py

I get an error:

Fatal Python error: Interpreter not initialized (version mismatch?)


Abort trap

and I can confirm that it's running the script in the System python – the first two lines in the script are:

import sys
print sys.path

Which prints:

['/opt/myProj', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python23.zip', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages']

So why is Mac OS X not using the python spec'd in the shebang?

(I also checked the line endings – unix.)

My name is Steve Ivy and I write about technology, the open web, social software, and general nerdity on monkinetic.com. You should follow me on Twitter or subscribe to this blog if you like what you're reading. I spend my days hacking Movable Type, python, Django, and various other efforts at Wallrazer. This is my personal site.