简体   繁体   中英

Installing mysqldb with a new version of python on linux

I have mysqldb installed and it works for python2.4. But I've recently installed python2.6 and when I run it I can't import mysqldb. I get the following:

import MySQLdb
ImportError: No module named MySQLdb

I've looked over how to install mysqldb (it's been a few years since I installed it), but can't find anything on how to reinstall or make it work with a new version of python. Any thoughts?

I made some progress by adding a path to my .bashrc file (the first one, whic is where my MySQLdb installation is for python2.4):

export PYTHONPATH=/usr/lib64/python2.4/site-packages:/usr/lib/python2.4:/usr/lib/python2.4/site-packages:$PYTHONPATH

so now when I run python2.6 and try import MySQLdb I get

import MySQLdb

Traceback (most recent call last):

File "", line 1, in

File "/usr/lib64/python2.4/site-packages/MySQLdb/ init .py", line 27, in import _mysql

ImportError: /usr/lib64/python2.4/site-packages/_mysql.so: undefined symbol: Py_InitModule4

I don't know what to do about this. Maybe install MySQLdb again with python2.6? (I've actually tried this and it's hard to install MySQLdb with or without setuptools. I did it once more than a year ago but forgot what I did. My server behind a firewall, so setuptools doesn't work out of the box.) Any ideas?

Which python version is on your path? You can determine this by typing

which python

It should return the location with py26 if it's referencing version 2.6

Then, try

sudo apt-get install python-mysqldb

This should install the correct version for 2.6

You can also download python-mysqldb directly here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM