0

TL;DR

Why does matplotlib's config end up inside $HOME when, installed inside virtualenv, should be scoped to the virtualenv's own site-packages?

Working on Tensorflow project, I

  • created virtualenv
  • activated virtualenv
  • then installed packages like Tensorflow, matplotlib, et al. [note: I do not have these packages installed globally]

In debugging matplotlib error, noticed comment about matplotlib from this answer [https://stackoverflow.com/a/21789908]

why is there a folder .matplotlib in my root folder instead of in the virtual environment where I installed it?

Per matplotlib docs [https://matplotlib.org/faq/troubleshooting_faq.html#matplotlib-configuration-and-cache-directory-locations]:

On unix-like systems, this directory is generally located in your HOME directory under the .config/ directory

using this simple script run from inside virtualenv , I confirm directory location on MacOS [10.10.5]

import matplotlib as mpl

print(mpl.get_cachedir())
# output is '$HOME/.matplotlib'

The docs, however, do not answer the question: why, when virtualenv installs should be scoped to the virtualenv's own site-packages, does matplotlib's config end up inside $HOME?

Zach Valenta
  • 1,783
  • 1
  • 20
  • 35

1 Answers1

0

Because they implemented a lot of other means.

matplotlib looks for matplotlibrc in four locations, in the following order:

matplotlibrc in the current working directory, usually used for specific customizations that you do not want to apply elsewhere.

$MATPLOTLIBRC if it is a file, else $MATPLOTLIBRC/matplotlibrc.

It next looks in a user-specific place, depending on your platform:

On Linux and FreeBSD, it looks in .config/matplotlib/matplotlibrc (or $XDG_CONFIG_HOME/matplotlib/matplotlibrc) if you’ve customized your environment.

On other platforms, it looks in .matplotlib/matplotlibrc.

Put your matplotlibrc in the current directory (or run your programs in a directory with matplotlibrc). Or define MATPLOTLIBRC environment variable. In a virtual environment you can set and clear it automatically with preactivate/postdeactivate hooks.

Community
  • 1
  • 1
phd
  • 82,685
  • 13
  • 120
  • 165