Mysql – How to install MySQLdb on a Python 2.6 source build, on Debian Lenny

MySQLpython

I've installed Python 2.6 from source on my Debian Lenny server, as Lenny does not have the python2.6 package. So, my Python 2.5 has MySQLdb installed and working just fine because I installed the python-mysqldb package.

I figured I could just install MySQLdb from source, but because I have the Lenny python-dev package, it builds against 2.5:

# python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.5/MySQLdb
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.5 -c _mysql.c -o build/temp.linux-x86_64-2.5/_mysql.o -DBIG_JOINS=1 -fPIC
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.5/_mysql.o -L/usr/lib/mysql -lmysqlclient_r -o build/lib.linux-x86_64-2.5/_mysql.so

I don't want to run python setup.py install, because I'm afraid it's going to screw up MySQLdb on 2.5 — should I? I imagine it'd just overwrite 2.5 and do nothing to 2.6 — maybe there's an argument I can use to install to 2.6? I imagine that I would need also to build against 2.6, so how do I do this?

Best Answer

Turns out this is extremely easy! I realise now that it builds against whatever version of python you launch setup.py with - in my case I had python symlinked to python2.5

So, instead of running python, run python2.6:

# python2.6 setup.py build
running build
running build_py
creating build/lib.linux-x86_64-2.6
copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.6
creating build/lib.linux-x86_64-2.6/MySQLdb
-- snip --
Related Topic