Question

I have already installed numpy successfully and I'm now trying to install matplotlib. I am following the steps found on the following website:

http://matplotlib.org/faq/installing_faq.html#source-install-from-git

The error occurs after the following command:

python setup.py install

Here is the error:

Checking .pth file support in /usr/local/lib/python2.7/dist-packages/
error: can't create or remove files in install directory                                     '

The following error occurred while trying to add or remove files in the installation directory:

    [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/test-easy-install-24752.pth'

The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:

    /usr/local/lib/python2.7/dist-packages/

I am working as the administrator on my machine and (I think) have all the rights to read/write files:

administrator@ubuntu:/usr/local/lib/python2.7/dist-packages$ ll -a
total 8
drwxrwsr-x 2 root staff 4096 Aug 20  2013 ./
drwxrwsr-x 4 root staff 4096 Mar  9 11:04 ../

What is the problem and how do I fix it?

Was it helpful?

Solution

I am working as the administrator on my machine and (I think) have all the rights to read/write files

This is really a discussion more suited to SuperUser, but the problem is that being an 'administrator' doesn't really mean what you think it does. In this line:

drwxrwsr-x 2 root staff 4096 Aug 20  2013 ./

root is the owner of the directory, and the final r-x means that other users are only allowed to read and execute, not write to this directory (see here for more details).

What can you do?

  1. Run the install command as root, e.g. $ sudo python setup.py install. This is NOT RECOMMENDED! The problem with installing system-wide Python modules in this way is that other package managers (e.g. apt-get) are totally oblivious to any changes made in this way, which tends to lead to a mess of broken dependencies for other system packages.

  2. Install the package from the Ubuntu repositories, i.e. $ sudo apt-get install python-matplotlib. This is probably the easiest way to install matplotlib, and is very unlikely to break any dependencies. However, the Ubuntu repositories tend to contain somewhat older versions of most Python packages.

  3. Install it into a virtualenv. This is safe, in that it doesn't affect anything in your global site-packages, and it allows you to install the very latest bleeding-edge versions. However, installing matplotlib into a virtualenv can be tricky, since matplotlib has lots of backend dependencies that generally need to be installed system-wide. To work around this you could either:

    a) Create your virtualenv with the --system-site-packages flag. With this option, if Python tries to import a module that isn't installed locally in your virutalenv's site-packages directory, it will then look in the system-wide site-packages. This means that you can install matplotlib locally in your virtualenv and it will find all of its backend dependencies in the system-wide site-packages. The downside is that if you have the same module installed both locally and system-wide, you have to be a bit more careful about version is actually being imported.

    b) Create your virtualenv with the --no-site-packages flag, then make symbolic links to the required modules in your system-wide site-packages directory. This blog article gives a good set of instructions for installing matplotlib inside a virtualenv using symlinks. This method is trickier, but the advantage is that your virtualenv is (almost!) completely self-contained, and there can be no doubt about where your module imports are coming from.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top