Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matplotlib requires sudo on Ubuntu 14.04 for me #3960

Closed
skarthikkrishna92 opened this issue Jan 1, 2015 · 11 comments
Closed

Matplotlib requires sudo on Ubuntu 14.04 for me #3960

skarthikkrishna92 opened this issue Jan 1, 2015 · 11 comments

Comments

@skarthikkrishna92
Copy link

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 "Q1.py", line 2, in <module>
import matplotlib.pyplot as plt

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

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

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

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

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

File "/usr/lib/pymodules/python2.7/matplotlib/font_manager.py", line 1356, in <module>
_rebuild()

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

File "/usr/lib/pymodules/python2.7/matplotlib/font_manager.py", 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

EDIT :

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

/home/skarthikkrishna/.config/matplotlib

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

/tmp/matplotlib-skarthikkrishna

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

https://stackoverflow.com/questions/27667641/matplotlib-requires-sudo-on-ubuntu-14-04

@WeatherGod
Copy link
Member

Are the user names the same on both systems? I also find it curious that it
is trying to put the font list cache in the /tmp directory. Are you getting
the same output for get_configdir() and get_cachedir() on both systems?

On Thu, Jan 1, 2015 at 11:17 AM, skarthikkrishna92 <notifications@github.com

wrote:

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 "Q1.py", line 2, in
import matplotlib.pyplot as plt

File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 24, in
import matplotlib.colorbar

File "/usr/lib/pymodules/python2.7/matplotlib/colorbar.py", line 29, in
import matplotlib.collections as collections

File "/usr/lib/pymodules/python2.7/matplotlib/collections.py", line 23, in
import matplotlib.backend_bases as backend_bases

File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 50, in
import matplotlib.textpath as textpath

File "/usr/lib/pymodules/python2.7/matplotlib/textpath.py", line 11, in
import matplotlib.font_manager as font_manager

File "/usr/lib/pymodules/python2.7/matplotlib/font_manager.py", line 1356, in
_rebuild()

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

File "/usr/lib/pymodules/python2.7/matplotlib/font_manager.py", 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

EDIT :

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

/home/skarthikkrishna/.config/matplotlib

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

/tmp/matplotlib-skarthikkrishna

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

https://stackoverflow.com/questions/27667641/matplotlib-requires-sudo-on-ubuntu-14-04


Reply to this email directly or view it on GitHub
#3960.

@skarthikkrishna92
Copy link
Author

@WeatherGod - I remember making sure that the user names on both systems were the same. I don't have access to the other system right now, so I can't be one hundred percent sure. I'll find the answers to both the questions and update the thread as soon as I get my hands on my old system

@efiring
Copy link
Member

efiring commented Jan 1, 2015

In transferring your identity and files from one machine to another, it is not just a matter of user name and group name, but also of their respective numbers, UID and GID, set in the /etc/passwd and /etc/group files.
The fact that mpl is using /tmp means that it could not write to the expected location in your home directory, which is puzzling; but the second puzzle is why it apparently can't write to /tmp.
In any case, all this has nothing to do with matplotlib and Ubuntu 14.04 in general; it is a problem specific to your installation.

Try this: use the standard gui tool (whatever is provided with the desktop environment you are using) to create a new user account with some other name. Then log out of your present account and into the new one, and try running something in matplotlib. You should find that it is no longer using /tmp, but a newly-created subdirectory in your home directory.

I think the cache dir should be ~/.cache, but this can be changed depending on your environment variables. You can see what it is in your test user account, and then check to see if this can be created and is writable in your real user account.

@cel4
Copy link

cel4 commented Jan 1, 2015

@efiring, if that is the issue, ls -ld /home/skarthikkrishna/.config/matplotlib should show user and group ids instead of names. If copied from a root account, maybe root still owns this directory? Anyway, chown -R <username>: /home/skarthikkrishna/.config/matplotlib should fix this issue in this case.

What really confused me is, that writing to the folder in tmp is apparently not possible. the tmp directory has full permissions: drwxrwxrwt. No matter what user you are, you really should be able to create a folder there. Does matplotlib try to create the temp folder if it does not exist?

Anyway it might be a good idea to catch this case and report permission issues. In my opinion, if matplotlib cannot write to its config directory, this is probably always a bad sign. The fallback to the tmp directory is fine, but an explicit warning about permission issues might be a good idea.

@tacaswell tacaswell added this to the unassigned milestone Jan 2, 2015
@pelson
Copy link
Member

pelson commented Jan 4, 2015

Anyway it might be a good idea to catch this case and report permission issues. In my opinion, if matplotlib cannot write to its config directory, this is probably always a bad sign. The fallback to the tmp directory is fine, but an explicit warning about permission issues might be a good idea.

I'd be 👍 on that idea. I'll close this original issue, but if you wanted to get involved and submit a PR for the warning, I think it would be a welcome addition.

Thanks!

@pelson pelson closed this as completed Jan 4, 2015
@skarthikkrishna92
Copy link
Author

@cel4 - Sorry I couldn't get back earlier. I've tried taking control of the config folder using chown. While it doesn't throw up any errors, I still find that I require sudo to run any code that requires matplotlib

@aberaud
Copy link

aberaud commented Jul 13, 2015

I had the issue, fixed it by deleting $HOME/.cache/matplotlib that happened to be owned by root.

@donsummerwind
Copy link

@aberaud +1 works for me

@jessecooper
Copy link

I am having this issue with a system user when I am trying to make my app a *nix daemon. The system user is running the program and this system user does not have a /home/[user] file since it is a system user. Now the system user is able to make files in the /tmp dir but it looks as if matplotlib is not making the tmp dir before trying to use it.

Mar 12 18:28:09 goldenidol picam[15617]: OSError: [Errno 2] No such file or directory: '/tmp/matplotlib-HoH6uY' 

My work around is going to be to make this a account instead of a system service account but this is not ideal.

@anntzer
Copy link
Contributor

anntzer commented Mar 12, 2018

Can't reproduce:

$ sudo su -s /bin/bash nobody
[nobody@antony1 antony]$ python -c 'import matplotlib; print(matplotlib.get_home(), matplotlib.get_configdir(), matplotlib.get_cachedir())'
/ /tmp/matplotlib-_yu6e_ak /tmp/matplotlib-_yu6e_ak

@jessecooper
Copy link

jessecooper commented Mar 12, 2018

I got it to work with the service account. Seemed to be a supplemental group I needed to add to that service account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants