[Errno 13] Permission denied: ‘/root/.python-eggs’ [SOLVED]

A few days ago I had to install MySQLdb. The installation is quite simple:

# tar -xzvf MySQL-python-1.2.2.tar.gz
# cd MySQL-python-1.2.2
# python setup.py build
# python setup.py install

But then I checked a page which had to use this python module (MySQLdb) and… oops, it did not work:

    Can't extract file(s) to egg cache
    The following error occurred while trying to extract file(s) to the Python <b>egg cache</b>:
    [Errno 13] Permission denied: '/root/.python-eggs'
    The Python egg cache directory is currently set to:
    /root/.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.

The problem was obviously that apache user did not have rights to write into /root/.python-eggs so the page crashed. A simple export of that variable pointing to a directory into which apache user can write will do the trick *temporarily*

# export PYTHON_EGG_CACHE=/var/www/.python-eggs/

But I wanted this variable to be *permanently* set to that dir… so I thought a “SetEnv” in apache configuration would do the job. But it did not.

Two different fixes

1) Assuming your test server runs newer Invenio with mod_wsgi, you can try http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonEggs
or its equivalent for mod_python.

2) Otherwise you can always install Python modules uncompressed, for mod_wsgi or mod_python, then the egg decompression would not be needed upon runtime, so no problem with privileges. If packages such as MySQLdb were installed as Python eggs, and the directory setup is done so that Apache user cannot decompress them upon Apache startup, an error like the one shown above is usually seen.

This can be solved by simply installing the problematic module uncompressed:

$ cd /Library/Python/2.3/site-packages/ (or /usr/lib64/python2.4/site-packages/ or wherever your site-packages are)
$ file MySQL_python-1.2.2-py2.3-macosx-10.4-i386.egg
$ unzip -t MySQL_python-1.2.2-py2.3-macosx-10.4-i386.egg
$ mv MySQL_python-1.2.2-py2.3-macosx-10.4-i386.egg foo.zip
$ mkdir MySQL_python-1.2.2-py2.3-macosx-10.4-i386.egg
$ cd MySQL_python-1.2.2-py2.3-macosx-10.4-i386.egg/
$ unzip ../foo.zip
$ rm ../foo.zip

Working nice and smoooth :)

Related posts:

  1. Python: how do I check the variable type? [solved]
  2. CDS-Invenio: [notice] mod_python: (Re)importing module ‘mod_python.publisher’
  3. Python: autocomplete names with tab key [solved]
  4. Python & Oracle [SOLVED] ImportError: libclntsh.so.11.1: wrong ELF class: ELFCLASS32
  5. CDS-Invenio: compress CSS to speed up page load

3 Responses to “[Errno 13] Permission denied: ‘/root/.python-eggs’ [SOLVED]”

Leave a Reply

Paypal donate

Please help me keep this blog up by donating.

Por favor, ayúdame a continuar con el blog donando.