Postgresql – How to install psycopg2 for multiple python interpreters on a CentOS box

centos5postgresqlpython

I have a CentOS 5.5 box, which comes preloaded with Python 2.4. I wanted 2.6, so used yumto get it from the EPEL repository. I also used yum to install the psycopg2 package, but it installed it for Python 2.4.

I tried copying /usr/lib/python2.4/site-packages/psycopg2/ to /usr/lib/python2.6/site-packages/, and when I ran my script, it worked… but it gave me a warning that said

/usr/lib/python2.6/site-packages/psycopg2/__init__.py:69: RuntimeWarning: Python C API version mismatch for module _psycopg: This Python has API version 1013, module _psycopg has version 1012.

So it looks like there's some kind of versioning issue going on here, and I'm wondering what the best way to fix it is. Should I just ignore the warning and carry on? Is there a way to use yum to install psycopg2 for Python 2.6? Should I just install from source using python26 setup.py install? I know installing from source is generally a no-no in CentOS, so I want this to be a last resort, unless it's the only option. I just don't want to mess up yum.

Best Answer

I tried copying /usr/lib/python2.4/site-packages/psycopg2/ to /usr/lib/python2.6/site-packages/...

That is not supposed to work.

If you want psycopg2 available to multiple python interpreters, you have a few options... I like virtualenv for juggling multiple python installations on a system. This way you can have as many combinations of sandboxed module versions as you like.

If you just want to install psycopg2 where the Python2.6 libraries are, then we need to clarify python interpreters... let's assume Python2.6 is installed in /usr/bin/python26. I will assume you've satisfied the dependencies for psycopg2 in your Python2.6 install... at this point, download the psycopg2 tarball, untar, cd into the extracted archive directory, and (as root) run /usr/bin/python26 setup.py install. This will install psycopg2 for Python2.6.