views:

2068

answers:

4

Hey guys, I have a problem of upgrading python from 2.4 to 2.6:

I have CentOS 5 (Full)
It has python 2.4 living in /usr/lib/python2.4/
Additional modules are living in /usr/lib/python2.4/site-packages/

I've built python 2.6 from sources at /usr/local/lib/python2.6/
I've set default python to python2.6
Now old modules for 2.4 are out of pythonpath and are "lost"
In particular, yum is broken ("no module named yum")

So what is the right way to migrate/install modules to python2.6?

A: 

There are a couple of options...

  1. If the modules will run under Python 2.6, you can simply create symbolic links to them from the 2.6 site-packages directory to the 2.4 site-packages directory.

  2. If they will not run under 2.6, then you may need to re-compile them against 2.6, or install up-to-date versions of them. Just make sure you are using 2.6 when calling "python setup.py"

...

You may want to post this on serverfault.com, if you run into additional challenges.

gahooa
Thanks gahooa!Currently, there are around 100 modules in 2.4/site-packages. I am not very happy tp create 100 symbolic links...And to run setup.py I need to locate all sources and guess all dependencies for proper order of installation.I think there should be some "from the book" solution.
Yury Lifshits
+3  A: 

They are not broken, they are simply not installed. The solution to that is to install them under 2.6. But first we should see if you really should do that...

Yes, Python will when installed replace the python command to the version installed (unless you run it with --alt-install). You don't exactly state what your problem is, so I'm going to guess. Your problem is that many local commands using Python now fail, because they get executed with Python 2.6, and not with Python 2.4. Is that correct?

If that is so, then simply delete /usr/local/bin/python, and make sure /usr/bin/python is a symbolic link to /usr/bin/python2.4. Then you would have to type python2.6 to run python2,6, but that's OK. That's the best way to do it. Then you only need to install the packages you need in 2.6.

But if my guess is wrong, and you really need to install all those packages under 2.6, then don't worry too much. First of all, install setuptools. It includes an easy_install script, and you can then install modules with

easy_install <modulename>

It will download the module from pypi.python.org and install it. And it will also install any module that is a dependency. easy_install can install any module that is using distutils as an installer, and not many don't. This will make installing 90% of those modules a breeze.

If the module has a C-component, it will compile it, and then you need the library headers too, and that will be more work, and all you can do there is install them the standard CentOS way.

You shouldn't use symbolic links between versions, because libraries are generally for a particular version. For 2.4 and 2.6 I think the .pyc files are compatible (but I'm not 100% sure), so that may work, but any module who uses C will break. And other versions of Python will have incompatible .pyc files as well. And I'm sure that if you do that, most Python people are not going to help you if you do it. ;-)

In general, I try too keep the system python "clean", I.e. I don't install anything there that isn't installed with the packaging tools. Instead I use virtualenv or buildout to let every application have their own python path where it's dependencies live. So every single project I have basically has it's own set of libraries. It gets easier that way.

Lennart Regebro
Thanks!After reverting default python to 2.4, yum is back to life.
Yury Lifshits
A: 

Some Python libs may be still not accessible as with Python 2.6 site-packages is changed to dist-packages.

The only way in that case is to do move all stuff generated in site-packages (e.g. by make install) to dist-packages and create a sym-link.

wr
A: 

easy_install is good one but there are low level way for installing module, just:

  1. unpack module source to some directory
  2. type "python setup.py install"

Of course you should do this with required installed python interpreter version; for checking it type:

python -V

Denis Barmenkov