Skip to content

Installing MySQLdb Without Python Egg Problems

by Paul Kenjora on May 31st, 2008

When installing Django sooner or later you will come across a system that needs MySQLdb and sooner or later you will see the following error:

[Sat May 31 19:43:19 2008] [error] [client 99.165.134.196] PythonHandler django.core.handlers.modpython: ExtractionError: Can’t extract file(s) to egg cache\n\nThe following error occurred while trying to extract file(s) to the Python egg\ncache:\n\n [Errno 13] Permission denied: ‘/root/.python-eggs’\n\nThe Python egg cache directory is currently set to:\n\n /root/.python-eggs\n\nPerhaps your account does not have write access to this directory? You can\nchange the cache directory by setting the PYTHON_EGG_CACHE environment\nvariable to point to an accessible directory.\n

The fix is to set the PYTHON_EGG_CACHE environment variable before running the install. The install instructions do not make this clear and the error sounds like the path needs to be set after install. Here are the steps to avoid the above error.

  1. Download the tarball from SourceForge.
  2. $ tar zxvf [filename of MySQLdb tarball]
  3. $ cd [name of resulting directory]
  4. $ export PYTHON_EGG_CACHE=/var/cache/python-eggs
  5. $ mkdir /var/cache/python-eggs
  6. $ chmod 777 /var/cache/python-eggs
  7. $ python setup.py build
  8. $ python setup.py install

Thats it. I’ve only run into this issue on Fedora within Amazon EC2. Other platforms and versions of the MySQLdb module may work.

  • Sigh... then you will need the pyton development libraries.

    yum install python-devel
  • Then modify the broken include for uint in _mysql.c.

    Related Post
  • Then you will need to install mysql development libraries.

    yum install mysql-devel
  • You will also need GCC for the above install to work at step 7.

    yum install gcc
  • Also if you get a long list of _mysql.c errors then you probably forgot to install the python development tools.

    On fedora: yum install python-devel

    That one cost me some time.
  • Tim Wyatt
    Thanks for this, I had the same basic issue, with the slight differene that I was using easy_install to get the mysql_python package from pypi.

    Your post helped me understand what the issue was and after removing references to the package (from /site-packages/easy_install.pth) I deleted the egg and re-ran the procedure but this time with the -Z option, (easy_install -Z package) which unpacks the egg at the time of insallation into a subdir in the site-packages directory. This gets around the whole egg cache issue completely.
  • I know nothing about eggs, but I am guessing 777 isn't really what you want/need here. maybe some better chown-ing chmod-ing can be suggested.
blog comments powered by Disqus