3

On a native Mac OS X install, I see Python binary at /usr/bin at version 2.6

Recently I installed Python 2.7.2 from the official binaries and it installed it at /usr/local/bin

What path of the Python interpreter should I give in my #! which will be standardized across all platforms?

I am assuming it could be /usr/bin so that I may have to symlink /usr/bin/python to /usr/local/bin/python but I just wanted to sure before I do this

2 Answers 2

2

Nope. You would use env to find the python executable in $PATH and run it as appropriate.

#!/usr/bin/env python

print 'Hi mom!'
Sign up to request clarification or add additional context in comments.

2 Comments

But first you have to have the right directory on your PATH. For OS X Python framework installs, that's not necessarily obvious. /usr/local/bin isn't sufficient when you install third-party packages with scripts. You need to include the framework bin directory; various distributors of OS X Pythons use different locations for their framework roots.
Evangelize the python3!! print('Hi Mum!')
1

On Mac OS X, do not modify anything in /usr (including /usr/bin) other than /usr/local, nor anything in /System/Library. Those directory spaces are managed by Apple as part of OS X. You risk breaking your system if you change or delete the wrong thing there. The best way to manage different versions is to modify your shell PATH environment variable; then you can use /usr/bin/env if needed. You can also use shell aliases or just use absolute paths. The Python installers from python.org have an option to automatically modify your shell initialization files appropriately.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.