Matplotlib requires sudo on Ubuntu 14.04 for me

I recently shifted to a new laptop. After installing Ubuntu 14.04 LTS and all of the packages that my previous system contained, I copied all my files from my old system to the new one.

Whenever I try executing any python code that has a matplotlib call, I get the following error

File "", line 2, in <module>
import matplotlib.pyplot as plt

File "/usr/lib/pymodules/python2.7/matplotlib/", line 24, in <module>
import matplotlib.colorbar

File "/usr/lib/pymodules/python2.7/matplotlib/", line 29, in <module>
import matplotlib.collections as collections

File "/usr/lib/pymodules/python2.7/matplotlib/", line 23, in <module>
import matplotlib.backend_bases as backend_bases

File "/usr/lib/pymodules/python2.7/matplotlib/", line 50, in <module>
import matplotlib.textpath as textpath

File "/usr/lib/pymodules/python2.7/matplotlib/", line 11, in <module>
import matplotlib.font_manager as font_manager

File "/usr/lib/pymodules/python2.7/matplotlib/", line 1356, in <module>

File "/usr/lib/pymodules/python2.7/matplotlib/", line 1343, in _rebuild
pickle_dump(fontManager, _fmcache)

File "/usr/lib/pymodules/python2.7/matplotlib/", line 939, in pickle_dump
with open(filename, 'wb') as fh:

IOError: [Errno 2] No such file or directory: '/tmp/matplotlib-skarthikkrishna/fontList.cache'

From what I’ve been able to try, this problem seems to crop up because the code cannot access /tmp/ for writing onto it. The code runs just fine when I add a sudo tag before the execution command.

I’m curious as to why this is happening now. All the packages on my old and new laptop, especially the pyplot package are the same. I haven’t missed out on installing any package, nor has there been any update that is not reflected in one of the systems. The code runs just fine in my old laptop. It refuses to work without sudo in the new one. I’d appreciate it if someone could help me out on that

A few details, if they are relevant:

Both systems run Ubuntu 14.04 LTS, last upgraded on 26th Dec, 2014.

I’m running Python 2.7.6 on both systems. [It’s a mandated requirement for most of my coursework]

Matplotlib version installed on both systems is 1.3.1


The output of ls -ld /tmp/ is

drwxrwxrwt 4 root root 4096 Dec 27 18:45 /tmp/

The output of ls -ld /tmp/matplotlib-skarthikkrishna is

ls: cannot access /tmp/matplotlib-skarthikkrishna: No such file or directory

The output remains the same with and without sudo, if at all that is relevant.

I used sudo apt-get install python-matplotlib to install matplotlib on both systems

The output of python -c "import matplotlib; print(matplotlib.get_configdir())" is


The output of python -c "import matplotlib;print(matplotlib.get_cachedir())" is


All the permission have been set appropriately to the best of my knowledge, but I’m not very sure about that. The stackoverflow thread for this is located at

Author: Fantashit

1 thought on “Matplotlib requires sudo on Ubuntu 14.04 for me

Comments are closed.