MySQLdb FAQ: Compiling _mysql.so

Next Previous Contents

## 1. Compiling `_mysql.so`

Here are some common errors that happen during the build. This section covers UNIX/Linux problems only, as I don't do Windows. `.so` is a dynamically loading library on Linux and most other UNIX variants; a few use extensions other than `.so`. Windows probably uses `.dll`.

## 1.1 ImportError: libmysqlclient.so.6: cannot open shared object file: No such file or directory

You have dynamic MySQL libraries, and by default, your compiler links `_mysql.so` against these, but these are not on your loader path when you start Python. You have two basic options:

1. Modify setup.py so that it links against the static library; see the comments.
2. If your linker supports a run-time loader path switch, you can set this in setup.py as well.
3. Change your system environment so that the MySQL libraries are on your loader path. With Linux, you can modify `/etc/ld.so.conf` (see `man ldconfig` for more details) or you can add to or create the `LD_LIBRARY_PATH` environment variable before starting Python, i.e.

       LD_LIBRARY_PATH=/path/to/mysql/libs python ... # Bourne-ish shell

## 1.2 ImportError: ./_mysql.so: undefined symbol: PyLong_FromUnsignedLongLong

`PyLong_FromUnsignedLongLong()` first appears in Python 1.5.2, so you are linking against an earlier version. You may also have more than one version installed. Get Python 1.5.2 or newer from your vendor or python.org.

## 1.3 ImportError: ./_mysql.so: undefined symbol: uncompress

It seems that MySQL-3.23 client libraries require libz for gzip compression. setup.py should add this automatically.

## 1.4 ./_mysql.c:33: mysql.h: No such file or directory

The include path (-I) to your MySQL include files is wrong; modify setup.py. OR: You don't have the MySQL development stuff loaded. If you are using the Red Hat RPMs, you need the `MySQL-devel` RPM to compile `_mysql.so`. However, if you link against the static MySQL libraries (see above), you can install `_mysql.so` on a system that does not have the MySQL client libraries (`libmysqlclient`).

## 1.5 I'm using Windows...

Say no more.

I don't use Windows. setup.py is supposed to work for building. There may also be a link to some user-contributed binaries on the web site.

Next Previous Contents