Matplotlib在Ubuntu 14.04上需要sudo [英] Matplotlib requires sudo on Ubuntu 14.04

查看:48
本文介绍了Matplotlib在Ubuntu 14.04上需要sudo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近转移到了新笔记本电脑上.安装Ubuntu 14.04 LTS和以前的系统包含的所有软件包之后,我将所有文件从旧系统复制到了新系统.

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.

每当我尝试执行具有matplotlib调用的任何python代码时,都会收到以下错误消息

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'

根据我的尝试,似乎出现了此问题,因为代码无法访问/tmp/进行写入.当我在执行命令之前添加sudo标记时,代码可以正常运行.

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.

我很好奇为什么现在会发生这种情况.我的新旧笔记本电脑上的所有软件包,尤其是pyplot软件包都是相同的.我没有错过安装任何软件包的机会,也没有任何未反映在其中一个系统中的更新.该代码可以在我的旧笔记本电脑上正常运行.它拒绝在新的没有 sudo 的情况下工作.如果有人可以帮助我,我将不胜感激

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

一些相关的详细信息:

这两个系统都运行Ubuntu 14.04 LTS,最后一次更新是在2014年12月26日.

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

我在两个系统上都运行Python 2.7.6.[这是我大部分课程的法定要求]

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

Matplotlib版本是1.3.1

Matplotlib version installed on both systems is 1.3.1

ls -ld/tmp/的输出是

The output of ls -ld /tmp/ is

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

ls -ld/tmp/matplotlib-skarthikkrishna的输出是

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

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

如果有任何相关性,则使用sudo和不使用sudo的输出将保持不变.

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

推荐答案

这是为我工作的解决方案:

This is the solution, worked for me:

sudo rm -rf $HOME/.cache/matplotlib

感谢aberaud 评论于2015年7月14日

Thanks to aberaud commented on Jul 14, 2015

我遇到了问题,通过删除碰巧由root拥有的$ HOME/.cache/matplotlib来解决此问题.

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

这篇关于Matplotlib在Ubuntu 14.04上需要sudo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆