【发布时间】:2014-05-13 11:24:25
【问题描述】:
我已经成功安装了 numpy,我现在正在尝试安装 matplotlib。我正在按照以下网站上的步骤进行操作:
http://matplotlib.org/faq/installing_faq.html#source-install-from-git
执行以下命令后出现错误:
python setup.py install
这是错误:
Checking .pth file support in /usr/local/lib/python2.7/dist-packages/
error: can't create or remove files in install directory '
The following error occurred while trying to add or remove files in the installation directory:
[Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/test-easy-install-24752.pth'
The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:
/usr/local/lib/python2.7/dist-packages/
我在我的机器上以管理员身份工作,并且(我认为)拥有读/写文件的所有权限:
administrator@ubuntu:/usr/local/lib/python2.7/dist-packages$ ll -a
total 8
drwxrwsr-x 2 root staff 4096 Aug 20 2013 ./
drwxrwsr-x 4 root staff 4096 Mar 9 11:04 ../
有什么问题,我该如何解决?
【问题讨论】:
-
你可以尝试在 virtualenv 中工作 (virtualenv.readthedocs.org/en/latest)
-
@daouzli 在
virtualenv中安装matplotlib相当棘手,因为后端依赖项通常需要在系统范围内安装。由于 OP 使用的是 Ubuntu,因此安装matplotlib的最简单方法可能就是$ sudo apt-get install python-matplotlib。如果 OP 绝对有必要在virtualenv中从源代码构建它,那么 this guide 可能会有所帮助。 -
@ali_m
sudo命令确实起到了作用,谢谢。但是知道为什么即使我拥有所有足够的权限它也无法创建文件? -
检查
/usr/local/lib/python2.7/dist-packages/的权限——几乎可以肯定它只能由root写入。以“管理员”身份登录通常意味着您在sudoers列表中,但并不意味着您的普通登录 shell 可以写入系统文件(这是一件非常好的事情!)。一般来说,我强烈建议不要使用sudo安装 Python 包,使用pip、easy_install或setup.py。您可能会陷入真正的混乱,因为其他包管理器(例如apt-get)不知道以这种方式进行的任何更改。 -
@ali_m 请将其发布为答案。我倾向于使用混合系统来安装 mpl,gui-toolkit 的东西在安装的系统范围内(就像 BLAS 公司一样),我在 venv 中安装 mpl、np、scipy、ipython ……(使用系统包) .
标签: python linux numpy matplotlib