无法使用easy_install安装Python模块

15 投票
6 回答
82036 浏览
提问于 2025-04-17 03:30

我正在尝试使用 easy_install 来安装一个叫做 requests 的模块,方法是这样做:

easy_install requests

一周前我用的是 Python 2.6.5,这个方法运行得很好。但今天我安装了 Python 2.7.2,然后在我的一个脚本中尝试 import requests,结果失败了。于是我又尝试用 easy_install requests 重新安装 requests,但出现了这个错误:

install_dir /usr/local/lib/python2.6/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.6/dist-packages/test-easy-install-15207.pth'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/local/lib/python2.6/dist-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  http://packages.python.org/distribute/easy_install.html

Please make the appropriate changes for your system and try again.

有人告诉我去重新安装 easy_install,于是我去了 http://pypi.python.org/pypi/setuptools,了解到我需要:

首先,删除你系统的 site-packages 目录下的所有 setuptools*.egg 和 setuptools.pth 文件(还有其他 sys.path 目录中的文件)。

我照做了。然后我从 setuptools-0.6c11-py2.7.egg 重新安装了 setuptools。看起来安装成功了,但当我运行 easy_install requests 时,基本上还是出现了同样的错误,只不过目录从 python2.6/dist-packages 变成了 python2.7/site-packages。

siddhion@siddhion-laptop:~$ easy_install requests
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/site-packages/test-easy-install-16253.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/local/lib/python2.7/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  http://peak.telecommunity.com/EasyInstall.html

Please make the appropriate changes for your system and try again.

另外,当我按下 easy_install 并按下 tab 键时,出现了这些选项:

easy_install      easy_install-2.6  easy_install-2.7

为什么会有 easy_install-2.6 呢?

还有

我该如何让 easy_install 再次工作?

6 个回答

4

以下内容是在我使用Ubuntu 12.10时有效的,首先安装了easy_install,然后再安装pip

sudo apt-get install python-virtualenv
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python get-pip.py
5

在基于包管理的Linux系统上,你应该使用virtualenv。这样可以确保你的Python脚本不会和其他软件包发生冲突,也不会影响到操作系统的包管理工具。

http://workaround.org/easy-install-debian

16

你试过像这样使用 sudo 吗?

sudo easy_install requests

或者你可以指定一个你有写权限的安装目录。

easy_install --install-dir=/home/foo/bar

不过其实你应该使用 PIP,而不是 easy_install。PIP 更好用,功能也更多。

撰写回答