3

I've googled and searched stack overflow for solutions, but I can't seem to find any way to fix this. Basically, this is my problem: I'm trying to use the Image/PIL Python module, which comes preinstalled with Enthought's distribution, but not with the default OSX python distribution.

Note that the PIL/Image import does work on the enthought shell.

My shebang is

#!/usr/local/bin/python 

Is there an easy way to change the python version I'm using?

Thank you very much for any help.

EDIT: I found a solution. By typing "which python" in bash (without the quotes), I found the directory where the enthought distribution was stored. (/Library/Frameworks/Python.framework/Versions/Current/bin/python) for me. Then, I just had to change the hashbang to

#!/Library/Frameworks/Python.framework/Versions/Current/bin/python 
1
  • I don't have a well formulated answer, but I'll predict that one of your best answers will involve virtualenv. Commented May 12, 2013 at 3:26

2 Answers 2

2

Yes. virtualenv is the accepted way to isolate python environments so you can choose to use whichever python version you so desire.

While you can do exactly what you did in your question-self-answer above, switching the hashbang to

#!/Library/Frameworks/Python.framework/Versions/Current/bin/python 

you will begin to find things confusing when the number of your python scripts increase and you have to do "mass search and replace" just to make sure all your scripts point to the right python version.

So the recommendation is indeed to use virtualenv and its wrapper sister mkvirtualenv

And leave the hashbang in your python scripts alone.

And as mentioned by @shx2 below, use the portable shebang line

#! /usr/bin/env python 
Sign up to request clarification or add additional context in comments.

2 Comments

Should I just google it to find the correct version and install it, or is there a better way?
python --version gives you the current version of python that is installed system-wide. You should check out macports (if you are using Mac OS X) to find out how to download multiple versions of python and manage those versions using port select.
1

As far as I know, the most recommended / most portable shebang line is this:

#! /usr/bin/env python 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.