I have a couple different versions of Python installed on my Mac. The default version is 2.5, so when I install a module it gets installed to 2.5. I need to be able to install some modules to a different version of Python because I am working on projects that use different versions. Any one know how to accomplish this? Thanks for your help.
-
For a similar question, on installing modules with `easy_install` when different versions of python, installed with macports ara available, see http://stackoverflow.com/questions/5792060/easy-install-with-various-versions-of-python-installed-mac-osx – juanchopanza Jun 03 '11 at 07:18
3 Answers
If you're installing using setup.py, just run it via the appropriate version of Python, e.g.:
python2.6 setup.py install
If you're using easy_install there should be a version for the corresponding Python version called easy_install-N.N, e.g.
easy_install-2.6 some_module
If you're working on different projects that require different versions of Python, consider using virtualenv (and virtualenvwrapper) - it allows you to fire up and use multiple environments each with its own version of Python and set of libraries. Example usage would be something like:
$ python -V
Python 2.5.4
$ mkvirtualenv --python=python2.6 foo
foo $ python -V
Python 2.6.1
foo $ pip install some_mod # installs module in foo's library, rather
# than site wide
foo $ deactivate # leave the virtual env
$ python -m some_mod
/path/to/python: No module named some_mod
To go back to the foo environment later, use workon
:
$ workon foo
foo $ python -m some_mod # no error, apns available within the env
foo $
So you can use virtualenv to maintain separate environments for each version of Python you have installed. Within those environments, pip and easy_install just do the right thing.

- 20,506
- 4
- 62
- 79
-
How exactly do you get the version of easy_install that you need? None of the stuff I've ready is easy or points me to something that works. – Michael May 02 '14 at 22:28
-
If you're installing through setuptools (ie python setup.py
), it will install to the lib directory for the python executable you use (unless it's a broken package).

- 6,376
- 2
- 23
- 28
If you've installed them using macports then you run (as root):
port select --set python <python_version>
Hint: To list available versions run:
port select --list python
Otherwise you can set the $PYTHON_PATH
environment variable and add your desired python path to your $PATH
environment variable as well.
You will also need to update the python.current
(or something with similar name) symbolic link in /Library/Frameworks/Python.framework
.
I strongly recommend to install all the versions using a package manager (homebrew, macports, fink, etc.) so they'll be easier to manage.

- 20,031
- 6
- 53
- 68
-
`port install python_select` seems to proceed okay, but there is no `python_select` binary afterwards... – Michael May 02 '14 at 22:32
-
`python_select` is deprecated. Do `sudo port select --set python
(ex. python26)` instead. – fardjad May 03 '14 at 07:22