diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 3c7e1c923f1..df6c0c1ffa1 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -553,7 +553,13 @@ def _create_tmp_config_dir(): # Some restricted platforms (such as Google App Engine) do not provide # gettempdir. return None - tempdir = os.path.join(tempdir, 'matplotlib-%s' % getpass.getuser()) + + try: + username = getpass.getuser() + except KeyError: + username = str(os.getuid()) + tempdir = os.path.join(tempdir, 'matplotlib-%s' % username) + os.environ['MPLCONFIGDIR'] = tempdir mkdirs(tempdir)