Python 如何更改pip安装路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41650158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change pip installation path
提问by xtt
I am using Mac. My pip installation path is /Library/Python/2.7/site-packages
. How do I change it to ~/anaconda/lib/python2.7/site-packages/
?
我正在使用 Mac。我的 pip 安装路径是/Library/Python/2.7/site-packages
. 我如何将其更改为~/anaconda/lib/python2.7/site-packages/
?
Oftentimes, the package installed by pip won't be found by my jupyter notebook and that's why I want to change the path.
通常,我的 jupyter notebook 找不到 pip 安装的包,这就是我想更改路径的原因。
I appreciate your help. Other solutions for correctly installing packages are welcome.
我感谢您的帮助。欢迎使用其他正确安装软件包的解决方案。
回答by Ijaz Ahmad Khan
You can tell pip where to install the package. Use the -t
flag , that means the target directory where you want to install the package. Have have look at pip install --help
您可以告诉 pip 安装包的位置。使用-t
flag ,这意味着要安装包的目标目录。有看过pip install --help
-t, --target <dir> Install packages into <dir>. By default this will not replace existing
files/folders in <dir>. Use --upgrade to replace existing packages in <dir> with
new versions.
You can change this on permanent basis by changing the pip.iniconfiguration file. See this for detail: pip install path
您可以通过更改pip.ini配置文件永久更改此设置。有关详细信息,请参阅:pip install path
On Unix and Mac OS X the configuration file is:
在 Unix 和 Mac OS X 上,配置文件是:
$HOME/.pip/pip.conf
On Windows, the configuration file is: %HOME%\pip\pip.ini The %HOME% is located in
在 Windows 上,配置文件是: %HOME%\pip\pip.ini %HOME% 位于
C:\Users\Bob on windows assuming your name is Bob
You may have to create the pip.ini file when you find your pip directory. Within your pip.ini or pip.config you will then need to put (assuming your on windows) something like
当您找到 pip 目录时,您可能需要创建 pip.ini 文件。在您的 pip.ini 或 pip.config 中,您将需要放置(假设您在 Windows 上)类似的内容
[global]
target=C:\Users\<username>\Desktop
回答by Rodrigo Carvalho
On macOS go to /usr/local/bin/
.
在 macOS 上,转到/usr/local/bin/
.
Remove the link to pip:
删除指向 pip 的链接:
rm /usr/local/bin/pip
Create the new link pointing to the new installation:
创建指向新安装的新链接:
sudo ln -s /new path /usr/local/bin/pip