From c041352efdbb2a31d71171ffe523f95a9611b747 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Mon, 1 Feb 2016 15:09:21 -0500 Subject: [PATCH] Fix issues with getting tempdir when unknown uid Closes #5940 --- lib/matplotlib/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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)