安装Python setuptools时出现错误 - 没有这样的文件或目录:'/usr/local/lib/python2.7/site-packages/test-easy-install-8811.pth'

7

我正在尝试在一台我没有root访问权限的Linux机器上安装setuptools。我已经创建了虚拟python环境。

dgomez:~/download> which python
/home/dgomez/bin/python

当我执行以下操作时,出现错误:
/home/dgomez/bin/python ez_setup.py 

Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
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 2] No such file or directory: '/usr/local/lib/python2.7/site-packages/test-easy-install-8816.pth'

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

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

This directory does not currently exist.  Please create it and try again, or
choose a different installation directory (using the -d or --install-dir

选项(option)。

我想知道如何解决这个问题。在其他论坛中,有用户通过创建目录来修复它,但在我的情况下,我没有root访问权限,因此无法创建目录。谢谢。

更新

我运行了Python。

ez_setup.py --install-dir=/home/dgomez/lib/python2.7/site-packages/

您仍然收到错误提示:
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/home/dgomez/lib/python2.7/site-packages/

and your PYTHONPATH environment variable currently contains:

''
2个回答

5
错误信息告诉您该怎么做,使用--install-dir--prefix选项将软件包安装到虚拟Python安装路径而不是默认位置。可能是这样的:
/home/dgomez/bin/python ez_setup.py --prefix=/home/dgomez

或者使用 --install-dir 选项:

/home/dgomez/bin/python ez_setup.py --install-dir=/home/dgomez/lib/python2.7/site-packages

请注意,根据您的Python安装的site-packages目录的实际位置,您可能需要修改上述选项中使用的目录。
编辑:为解决您看到的新错误,您需要将该目录添加到PYTHONPATH环境变量中,您可以使用以下命令完成此操作:
export PYTHONPATH=$PYTHONPATH:/home/dgomez/lib/python2.7/site-packages/

如果您在Mac或GNU/Linux系统上使用bash,则可以将该行添加到您的~/.bashrc文件中,这样您就不需要手动运行它。


@amb1s1,我刚刚更新了我的答案,告诉你如何设置PYTHONPATH环境变量。 - Andrew Clark
帮了我,谢谢你。只是别忘了在保存新的~./bashrc文件后重新启动你正在使用的终端。 - Or b

1
我遇到了同样的问题。不知何故,这个目录被删除了,所以我就没有pip和setuptools了。我的解决方法是直接从pip website下载pip。 我通过从get-pip.py下载pip文件来解决它。下载完成后,只需在python目录中运行此文件,您就可以再次使用这些setuptools。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接