views:

605

answers:

2

Via fink install I put the following Python version on my Mac OS X computer:

  • python2.3,
  • python2.4,
  • python2.5,
  • python2.6.

Further, python is alias for python2.6 on my system.

  1. I want to install an egg, e.g. easy_install networkx-0.36-py2.5.egg, where I have to use python 2.5 instead of version 2.6. Is this possible without changing the python alias?

  2. Can you tell me, whether and how I can install networkx-0.36-py2.5 and networkx-1.0rc1-py2.6 in parallel?

  3. How can I install a site-package in a way, that it is available for different Python versions?

+2  A: 

Edit: Read Ned Deily's answer before you read this one


1.

On my system I have different easy_install script for each python version:

  • /usr/bin/easy_install-2.5
  • /usr/bin/easy_install-2.6

The contents of the 2.6 version looks like this:

#!/System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
import sys
sys.argv[0] = sys.argv[0].replace('-2.6', '')
# EASY-INSTALL-ENTRY-SCRIPT: 'setuptools==0.6c9','console_scripts','easy_install'
__requires__ = 'setuptools==0.6c9'
import sys
from pkg_resources import load_entry_point

sys.exit(
   load_entry_point('setuptools==0.6c9', 'console_scripts', 'easy_install')()
)

Now, if you not already have those scripts on you machine, you could create those by using the above as template. Just change the first line so it points to the right python interpreter. Probably something like:

#!/sw/bin/python23

And change the third line to match the current script name; meaning, if the script is called easy_install-2.3, then it should look like this:

sys.argv[0] = sys.argv[0].replace('-2.3', '')

And of course if you are not using setuptools version 0.6c9 than you will have to change this, too.


An alternative is to run the easy_install script as an argument of the right python version. Like this:

$ python23 /some/path/easy_install networkx-0.36-py2.5.egg

2.

Each python version has a different site-lib, so they are independent from each other. You can install different modules and versions for different python versions

3.

You could make the env variable PYTHONPATH point to a common directory or add a common directory to sys.path in your scripts. But be aware that some modules work only with certain python versions and include C code that has to be compiled for each python version...

f3lix
The /usr/bin/easy_install-2.x commands are supplied by Apple for the Apple-supplied pythons. Installing the Fink setuptools packages is the easy and proper way to get easy_install-2.x commands for the Fink-installed pythons.
Ned Deily
I have not used fink and assumed fink did not provide the necessary scripts. So I tried to describe how to create them yourself... Given that fink _has_ packages containing those scripts, it's obviously better to use those fink packages.
f3lix
Thanks. And, for the record, MacPorts (Fink's main competitor on OS X) provides similar versioned setuptools packages for its python2.x packages.
Ned Deily
+2  A: 

easy_install is part of the setuptools package. Fink has separate setuptools packages for python 2.5 and python 2.6:

fink install setuptools-py25 setuptools-py26

You can then download and install networkx to both versions:

/sw/bin/easy_install-2.5 networkx
/sw/bin/easy_install-2.6 networkx

If you need a particular version of the package:

/sw/bin/easy_install-2.5 networkx==0.36
/sw/bin/easy_install-2.6 networkx==0.36
Ned Deily