MySQLdb lays an egg

If you’ve got a Python CGI that uses MySQLdb and it mysteriously fails to display, you may want to check /var/log/httpd/error_log where you might find something like:


Traceback (most recent call last):
File "/Library/WebServer/CGI-Executables/test2.cgi", line 12, in
import MySQLdb
File "build/bdist.macosx-10.4-i386/egg/MySQLdb/__init__.py", line 19, in
File "build/bdist.macosx-10.4-i386/egg/_mysql.py", line 7, in
File "build/bdist.macosx-10.4-i386/egg/_mysql.py", line 4, in __bootstrap__
File "/sw/lib/python2.5/site-packages/pkg_resources.py", line 800, in resource_filename
self, resource_name
File "/sw/lib/python2.5/site-packages/pkg_resources.py", line 1228, in get_resource_filename
self._extract_resource(manager, self._eager_to_zip(name))
File "/sw/lib/python2.5/site-packages/pkg_resources.py", line 1250, in _extract_resource
self.egg_name, self._parts(zip_path)
File "/sw/lib/python2.5/site-packages/pkg_resources.py", line 880, in get_cache_path
self.extraction_error()
File "/sw/lib/python2.5/site-packages/pkg_resources.py", line 846, in extraction_error
raise err
pkg_resources.ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

[Errno 13] Permission denied: '/Library/WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.4-i386.egg-tmp'

The Python egg cache directory is currently set to:

/Library/WebServer/.python-eggs

Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.

As it says, you need to either create the directory and set the privileges (chown -R www:www /Library/WebServer/.python-eggs) or set the PYTHON_EGG_CACHE environment variable to a directory that’s writable by the user executing the cgi (probably www).

Leave a Reply

Your email address will not be published. Required fields are marked *