python安装目录的正确权限? [英] Proper permissions for python installation directory?
问题描述
我正在尝试第一次在服务器上使用python应用程序.我首先以root身份添加setuptools:
I'm trying to use a python app on a server for the first time. I started by adding setuptools as root:
[root@server mydirectory]# yum install python-setuptools
很酷.然后,我尝试setup.py:
Cool. Then I try setup.py:
[user@server mydirectory]$ python 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/lib/python2.4/site-packages/test-easy-install-25752.write-test'
此目录/usr/lib/python2.4/site-packages
由root拥有,因此很有意义.
This directory /usr/lib/python2.4/site-packages
is owned by root, so that makes sense.
我的问题是,我应该chmod site-packages目录,还是应该以root用户身份运行setup.py?
My question is, should I chmod the site-packages directory, or should I be running setup.py as root?
推荐答案
将系统内容作为非root用户安装的传统方法是使用sudo
.这就是为什么您在整个Python文档中都看到这样的原因:
The traditional way to install stuff system-wide as a non-root user is to use sudo
. Which is why you see things like this all over the Python docs:
sudo python setup.py install
有些人更喜欢使站点软件包可被某个开发"组写成组,因此您无需这样做. (这实际上是Mac软件包管理器Homebrew所做的.)
Some people prefer to instead make the site-packages group-writable by some "dev" group so you don't need to do this. (This is effectively what the Mac package manager Homebrew does.)
或者,您可以安装到每个用户的站点程序包中.并非每个项目都能做到这一点,但是任何基于现代setuptools
的东西都应该能够做到这一点.
Alternatively, you can install into per-user site packages. Not every project can do this, but anything based on modern setuptools
should be able to do so.
而且,当我们在安装它时,如果您要安装基于现代setuptools
的内容,则最好还是使用pip install .
而不是python setup.py install
.除其他好处外,这还可以创建egg-info文件,以便可以将该软件包检测为依赖项,将其卸载等.
And, while we're at it, if you're installing stuff based on modern setuptools
, it's probably better to pip install .
instead of python setup.py install
anyway. That will, among other benefits, create egg-info files so the package can be detected as a dependency, uninstalled, etc.
有关更多信息,请参见 Python打包用户指南.信息.
See the Python Packaging User Guide for more information.
最后,您可能需要考虑使用虚拟环境.在Python 3.3及更高版本中,尽管它没有将其内置为 venv
在3.4之前没有自己的pip
.使用早期版本的Python,您可以在PyPI上安装 virtualenv
.
Finally, you may want to consider using a virtual environment. With Python 3.3+, this is built in as venv
, although it doesn't have its own pip
until 3.4. With earlier versions of Python, you can install virtualenv
off PyPI.
许多用于Python(2.x或3.x)的托管服务器环境都预装了virtualenv
.如果不是,那么在整个系统范围内安装 it 当然会要求您是root用户……但是在那之后,您将能够将(大多数)其他软件包安装到每个项目的虚拟环境中,而不是整个系统范围
Many hosted server environments for Python (2.x or 3.x) come with virtualenv
pre-installed. If not, installing it system-wide will of course require you to be root… but after that, you will be able to install (most) other packages into per-project virtual environments instead of system-wide.
这篇关于python安装目录的正确权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!