On Thu, Nov 4, 2010 at 10:49 AM, Philip Semanchuk <phi...@semanchuk.com> wrote: > Hi all, > I've run into an aspect of matplotlib's setup that seems awkward. I'm seeing > this on Ubuntu, but I imagine it would happen on any *nix platform. > > If python is running under sudo the first time matplotlib is imported, then > matplotlib creates its config dir (~/.matplotlib) with root as the owner. > Subsequent attempts to import matplotlib while running python as a > non-privileged user result in this: > > ----------------------------------------------------------------- > RuntimeError: '/home/philip' is not a writable dir; you must set > /home/philip/.matplotlib to be a writable dir. You can also set environment > variable MPLCONFIGDIR to any writable directory where you want matplotlib > data stored > ----------------------------------------------------------------- > > A simple way to re-create this -- > 1. Delete or rename ~/.matplotlib > 2. sudo python -c "import matplotlib" > 3. python -c "import matplotlib" > > > This not-improbable real-world scenario would create ~/.matplotlib owned by > root -- > 1) Download app FooBar that has matplotlib as a dependency > 2) Install matplotlib > 3) Run FooBar's setup.py as sudo. It imports matplotlib, perhaps just to > ensure that matplotlib is installed and working. > > > We ran into a similar situation with our app ('sudo python setup.py install' > created desktop icons owned by root) and we resolved it by invoking chown > after using a getenv() call to sniff out who we really wanted to own the file. > > It looks like the diff below (untested!) applied to > lib/matplotlib/__init__.py would prevent this from happening. Does it seems > reasonable to add it? > > 474a475,485 >> if not sys.platform.lower().startswith("win"): >> # Ensure that we didn't just create a root-owned directory in the >> # user's HOME directory. That happens if this is being run under >> # sudo. If the SUDO_USER env. var (which contains the user that >> # invoked sudo) then we're running under sudo. If it doesn't >> # exist, we're not running under sudo. >> current_user = os.getenv("SUDO_USER") >> if current_user: >> subprocess.call(["chown", "-R", current_user, p])
I'm not sure how I feel about this. On one hand, it is a pain to have this not work under sudo. On the other, I consider the fact that $HOME is not set to "/root" when running as root to be a bit of a problem. Personally, the better solution to me would be to make sure $HOME is one of the variables that gets reset by sudo. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma ------------------------------------------------------------------------------ The Next 800 Companies to Lead America's Growth: New Video Whitepaper David G. Thomson, author of the best-selling book "Blueprint to a Billion" shares his insights and actions to help propel your business during the next growth cycle. Listen Now! http://p.sf.net/sfu/SAP-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users