为什么我无法在Centos 6 VPS上安装setuptools?
我正在尝试在一个Centos 6的VPS上安装Python2.7的setuptools,使用的是这个教程。当我到达“使用我们安装的Python(2.7.6)安装setuptools”这一步时,出现了这个错误:
[username@hotsname setuptools-1.4.2]$ python2.7 setup.py install
running install
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-1111.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:
https://pythonhosted.org/setuptools/easy_install.html
Please make the appropriate changes for your system and try again.
之前,我按照同一个Digital Ocean社区网站上的说明,给执行上述操作的用户赋予了root权限。当我尝试用sudo来完成这个任务时,出现了:
[username@hostname setuptools-1.4.2]$ sudo python2.7 setup.py install
[sudo] password for username:
sudo: python2.7: command not found
所以我有点困惑。我觉得我可能漏掉了什么简单的东西。Digital Ocean无法提供进一步的支持。我已经使用virtualenv很长时间了,知道安装后该怎么做,只是这次在设置Centos主机时遇到了麻烦。你能告诉我我缺少了什么吗?
谢谢!
2 个回答
0
现在,如果你想轻松安装setuptools和pip,可以用你的Python解释器运行这个文件:
你可能需要管理员权限来把它安装到系统的Python上(比如用 sudo python get-pip.py
)。
安装完成后,你可以通过以下方式升级pip和/或setuptools:
$ pip install -U setuptools
$ pip install -U pip
我建议在大多数Python开发中,你只需要以管理员身份安装setuptools、pip和virtualenv(如果你比较保守的话,可以只安装virtualenv)。之后,你可以使用virtualenv创建独立的Python环境,这样就不需要安装到系统的Python上,也不会影响系统中已安装的包。这样,其他的Python(和/或 pip
的调用)就不需要以管理员身份运行了。
0
切换到根用户解决了问题。谢谢你,CasualDemon。