简体   繁体   English

将 pip 包安装到 $HOME 文件夹

[英]Installing pip packages to $HOME folder

Is it possible?是否可以? When installing pip , install the python packages inside my $HOME folder.安装pip ,将 python 包安装在我的$HOME文件夹中。 (for example, I want to install mercurial , using pip , but inside $HOME instead of /usr/local ) (例如,我想安装mercurial ,使用pip ,但在$HOME而不是/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.我在一台 mac 机器上,只是考虑过这种可能性,而不是“污染”我的/usr/local ,我会使用我的$HOME

PEP370 is exactly about this. PEP370正是关于这一点。 Is just creating a ˜/.local and do a pip install package enough to make these packages to be installed only at my $HOME folder?只是创建一个˜/.local并执行pip install package足以使这些包仅安装在我的 $HOME 文件夹中吗?

While you can use a virtualenv , you don't need to. 虽然可以使用virtualenv ,但是您不需要。 The trick is passing the PEP370 --user argument to the setup.py script. 诀窍是将PEP370 --user参数传递给setup.py脚本。 With the latest version of pip , one way to do it is: 使用最新版本的pip ,一种方法是:

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/ . 这应该导致将hg脚本安装在$HOME/.local/bin/hg ,并将其余hg软件包安装在$HOME/.local/lib/pythonx.y/site-packages/

Note, that the above is true for Python 2.6. 请注意,以上内容适用于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. 在Python核心开发人员中,关于在Mac OS X上适合PEP370风格user安装的适当目录位置,存在一些争议 In Python 2.7 and 3.2, the location on Mac OS X was changed from $HOME/.local to $HOME/Library/Python . 在Python 2.7和3.2中,Mac OS X上的位置从$HOME/.local更改为$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/xy/bin/hg and $HOME/Library/Python/xy/lib/python/site-packages . 但是,目前,在2.7(和3.2,如果Python 3支持hg )上,上述位置将是$HOME/Library/Python/xy/bin/hg$HOME/Library/Python/xy/lib/python/site-packages

I would use virtualenv at your HOME directory. 我会在您的HOME目录中使用virtualenv。

$ 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. 然后,您还可以更改~/.(login|profile|bash_profile) ,这是您的shell将〜/ bin添加到PATH中的正确选择,然后pip|python|easy_install将是默认使用的那个。

You can specify the -t option ( --target ) to specify the destination directory. 您可以指定-t选项( --target )以指定目标目录。 See pip install --help for detailed information. 有关详细信息,请参见pip install --help 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: 例如,要在我的$HOME目录中安装说mxnet,请输入:

pip install -t /home/foivos/ mxnet

Short answer to your two questions grabbed from the other answers从其他答案中抓取的两个问题的简短答案

One

Yes是的

it is possible installing pip packages to $HOME instead of /usr/local/lib/ , but可以将 pip 包安装到$HOME而不是/usr/local/lib/ ,但是

Two

mkdir ˜/.local # then
pip install package 

is not enough.是不足够的。

You need你需要

pip install package --user

and the packages get installed to并且软件包被安装到

/home/user/.local/lib/python3.x/site-packages

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM