A solution to the /python2.7/site-packages/_mysql.so: undefined symbol: mysql_kill error

mysqlI use Django with MySQL and I this error bothers me almost every time I start a new project with a fresh new installation of Django and relevant Python packages. I use virtualenv to isolate my Python environment for each project. The problem that’s causing this error is that the Python MySQL libraries that are installed via aptitude (I am on Ubuntu) are too old and need to be recompiled.

To do that, I first remove the default installation:

sudo apt-get uninstall mysql-python

and then I use pip to download and compile the latest package. Before the compilation starts, we first need to install some dependencies:

sudo apt-get install package python-dev build-essential libmysqlclient-dev python-pip

Now we can install the up-to-date Python MySQL libraries:

pip install --upgrade python-mysql

This should solve the problem.

Bookmark the permalink.
  • postrational

    Thanks for the tip. In order to do this on my installation I had to use slightly different commands:

    apt-get remove python-mysqldb

    and

    pip install –upgrade MySQL-python

    • pkout

      Thanks for sharing! From reading online, I get the impression that python-mysqldb and mysql-python are the same packages, perhaps a few versions apart. Not sure, though.