问题描述
有可能吗?安装 pip
时,在我的$HOME
文件夹.(例如,我想安装 mercurial
,使用 pip
,但在 $HOME
而不是 /usr/local
>)
Is it possible? When installing pip
, install the python packages inside my $HOME
folder. (for example, I want to install mercurial
, using pip
, but inside $HOME
instead of /usr/local
)
我用的是 mac 机器,只是想过这种可能性,而不是污染"我的 /usr/local
,我会改用我的 $HOME
.
I'm with a mac machine and just thought about this possibility, instead of "polluting" my /usr/local
, I would use my $HOME
instead.
PEP370 正是关于这一点.只是创建一个 ˜/.local
并执行 pip install package
是否足以使这些包仅安装在我的 $HOME 文件夹中?
PEP370 is exactly about this. Is just creating a ˜/.local
and do a pip install package
enough to make these packages to be installed only at my $HOME folder?
推荐答案
虽然您可以使用 virtualenv
,但您不需要.诀窍是将 PEP370 --user
参数传递给 setup.py
脚本.使用最新版本的 pip
,一种方法是:
While you can use a virtualenv
, you don't need to. The trick is passing the PEP370 --user
argument to the setup.py
script. With the latest version of pip
, one way to do it is:
pip install --user mercurial
这将导致 hg
脚本安装在 $HOME/.local/bin/hg
中,其余的 hg 包安装在 $HOME/.local/lib/pythonx.y/site-packages/
.
This should result in the hg
script being installed in $HOME/.local/bin/hg
and the rest of the hg package in $HOME/.local/lib/pythonx.y/site-packages/
.
请注意,上述内容适用于 Python 2.6.Python 核心开发人员之间存在有点争议,关于 Mac OS X 上的适当目录位置是什么用于 PEP370 风格的 user
安装.在 Python 2.7 和 3.2 中,Mac OS X 上的位置从 $HOME/.local
更改为 $HOME/Library/Python
.这可能会在未来的版本中改变.但是,就目前而言,在 2.7(和 3.2,如果 Python 3 支持 hg
),上述位置将是 $HOME/Library/Python/xy/bin/hg
和 $HOME/Library/Python/xy/lib/python/site-packages
.
Note, that the above is true for Python 2.6. There has been a bit of controversy among the Python core developers about what is the appropriate directory location on Mac OS X for PEP370-style user
installations. In Python 2.7 and 3.2, the location on Mac OS X was changed from $HOME/.local
to $HOME/Library/Python
. This might change in a future release. But, for now, on 2.7 (and 3.2, if hg
were supported on Python 3), the above locations will be $HOME/Library/Python/x.y/bin/hg
and $HOME/Library/Python/x.y/lib/python/site-packages
.
这篇关于将 pip 包安装到 $HOME 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!