将pip软件包安装到$ HOME文件夹

问题:将pip软件包安装到$ HOME文件夹

可能吗?安装时pip,将python软件包安装在我的$HOME文件夹中。(例如,我想使用安装,但mercurial使用而不是)pip$HOME/usr/local

我在Mac机器上,只是考虑了这种可能性,而不是“污染”我的/usr/local$HOME而是使用我的。

PEP370正是与此有关。只是创建一个˜/.localpip install package足以将这些软件包安装在我的$ HOME文件夹中?

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)

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 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?


回答 0

虽然您可以使用virtualenv,但不需要。诀窍是将PEP370 --user参数传递给setup.py脚本。使用的最新版本pip,一种方法是:

pip install --user mercurial

这应导致hg脚本已安装在中$HOME/.local/bin/hg,而hg软件包的其余部分已安装在中$HOME/.local/lib/pythonx.y/site-packages/

请注意,以上内容适用于Python 2.6。一直有一些争议的关于什么是PEP370风格的Mac OS X上的相应目录位置Python的核心开发者user安装。在Python 2.7和3.2中,Mac OS X上的位置从更改$HOME/.local$HOME/Library/Python。这可能会在将来的版本中更改。但是,目前,在2.7(和3.2,如果hgPython 3支持的话)上,上述位置将是$HOME/Library/Python/x.y/bin/hg$HOME/Library/Python/x.y/lib/python/site-packages

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

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/.

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.


回答 1

我会在您的HOME目录中使用virtualenv。

$ sudo easy_install -U virtualenv
$ cd ~
$ virtualenv .
$ bin/pip ...

然后~/.(login|profile|bash_profile),您还可以更改,无论哪种方式都适合您的shell将〜/ bin添加到您的PATH中,然后pip|python|easy_install默认情况下使用。

I would use virtualenv at your HOME directory.

$ sudo easy_install -U virtualenv
$ cd ~
$ virtualenv .
$ bin/pip ...

You could then also alter ~/.(login|profile|bash_profile), whichever is right for your shell to add ~/bin to your PATH and then that pip|python|easy_install would be the one used by default.


回答 2

您可以指定-t选项(--target)来指定目标目录。请参阅pip install --help以获取详细信息。这是您需要的命令:

pip install -t path_to_your_home package-name

例如,要在我的$HOME目录中安装说“ mxnet”,请输入:

pip install -t /home/foivos/ mxnet

You can specify the -t option (--target) to specify the destination directory. See pip install --help for detailed information. This is the command you need:

pip install -t path_to_your_home package-name

for example, for installing say mxnet, in my $HOME directory, I type:

pip install -t /home/foivos/ mxnet