Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#16 closed defect (fixed)

Installation can create unwriteable matplotlib config dir

Reported by: flip Owned by: flip
Priority: major Milestone:
Component: install Version:
Keywords: Cc:

Description

This is a little tricky. It happens only on systems that use sudo (for us,
OS X and Linux).

On a system where matplotlib has never been used, if our setup.py is run
as sudo then matplotlib will be broken thereafter.

What happens is that the first time matplotlib is imported, it looks for its
config dir which is ~/.matplotlib by default. If it doesn't find it, it
creates it. When the directory is created by a Python process running as sudo,
the ~/.matplotlib directory is created and owned by root. When a
non-privileged user runs Python thereafter and tries to import matplotlib,
matplotlib finds that it can't write to its own config dir and dies with this
error:

$ python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py", line 739, in <module>
    rcParams = rc_params()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py", line 657, in rc_params
    fname = matplotlib_fname()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py", line 595, in matplotlib_fname
    fname = os.path.join(get_configdir(), 'matplotlibrc')
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py", line 248, in wrapper
    ret = func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py", line 468, in _get_configdir
    raise RuntimeError("'%s' is not a writable dir; you must set %s/.matplotlib to be a writable dir.  You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored "% (h, h))
RuntimeError: '/Users/me' is not a writable dir; you must set /Users/me/.matplotlib to be a writable dir.  You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored 

Note that this situation won't come up if (a) matplotlib was installed and
used by some other app before our setup.py runs or (b) our setup.py is run
as a non-privileged user.

The exact matplotlib code that controls this is in
lib/matplotlib/__init__.py in the function _get_configdir():
http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/__init__.py?revision=8766&view=markup#l449

IMHO this is a bug or at least a misfeature in matplotlib. I ran into a
similar problem in our setup.py (desktop icons we created were owned by root)
and I wrote code to work around it. However, even if the matplotlib developers
agree and fix it tomorrow, we need a workaround for the existing matplotlib
packages in the repositories of Ubuntu, Fedora, etc.

Change History (3)

comment:1 Changed 9 years ago by flip

BTW here's an easy recreate scenario that I've tested under both Ubuntu and OS X. It assumes you have matplotlib installed already.

  1. Delete ~/.matplotlib (or rename it)
  2. Run Vespa's setup.py dependency check as sudo. It doesn't matter if you run setup.py from an SVN folder or from the official install tarball. Here's the command --
    sudo python setup.py depcheck
    
  3. Execute this command and watch it fail --
    python -c "import matplotlib"
    
  4. Note that ~/.matplotlib is owned by root. Executing this fixes the problem (substituting your username for "philip") --
    chown -R philip:philip ~/.matplotlib
    

An even simpler scenario --

  1. Delete ~/.matplotlib (or rename it)
  2. sudo python -c "import matplotlib"
  3. python -c "import matplotlib"



comment:2 Changed 9 years ago by flip

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in r1430.

I'll communicate with the matplotlib folks about this and file a bug there if it's deemed necessary.

comment:3 Changed 9 years ago by flip

Better workaround applied in 1473.

To see the discussion I had on the matplotlib mailing list regarding this, search for "config dir owned by root".

http://www.google.com/search?q="config+dir+owned+by+root"+matplotlib

Note: See TracTickets for help on using tickets.