Question

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
Was it helpful?

Solution

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

OTHER TIPS

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

#! /usr/bin/env python
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top