Python 如何更改 pip 的默认安装位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24174821/
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 default install location for pip
提问by weskpga
I'm trying to install Pandas using pip, but I'm having a bit of trouble. I just ran sudo pip install pandas
which successfully downloaded pandas. However, it did not get downloaded to the location that I wanted. Here's what I see when I use pip show pandas
:
我正在尝试使用 pip 安装 Pandas,但遇到了一些麻烦。我刚刚运行sudo pip install pandas
它成功下载了熊猫。但是,它没有下载到我想要的位置。这是我使用时看到的pip show pandas
:
---
Name: pandas
Version: 0.14.0
Location: /Library/Python/2.7/site-packages/pandas-0.14.0-py2.7-macosx-10.9-intel.egg
Requires: python-dateutil, pytz, numpy
So it is installed. But I was confused when I created a new Python Project and searched under System Libs/lib/python
for pandas, because it didn't show up. Some of the other packages that I've downloaded in the past did show up, however, so I tried to take a look at where those were. Running pip show numpy
(which I can import with no problem) yielded:
所以它被安装了。但是当我创建一个新的 Python 项目并在下面System Libs/lib/python
搜索 pandas 时,我感到很困惑,因为它没有出现。但是,我过去下载的一些其他软件包确实出现了,因此我尝试查看它们的位置。运行pip show numpy
(我可以毫无问题地导入)产生:
---
Name: numpy
Version: 1.6.2
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requires:
Which is in a completely different directory. For the sake of confirming my error, I ran pip install pyquery
to see where it would be downloaded to, and got:
这是在一个完全不同的目录中。为了确认我的错误,我跑去pip install pyquery
看它会被下载到哪里,并得到:
Name: pyquery
Version: 1.2.8
Location: /Library/Python/2.7/site-packages
Requires: lxml, cssselect
So the same place as pandas...
所以和熊猫一样的地方......
How do I change the default download location for pip so that these packages are downloaded to the same location that numpy is in?
如何更改 pip 的默认下载位置,以便将这些包下载到 numpy 所在的相同位置?
Note: There were a few similar questions that I saw when searching for a solution, but I didn't see anything that mentioned permanentlychanging the default location.
注意:我在搜索解决方案时看到了一些类似的问题,但我没有看到任何提到永久更改默认位置的内容。
采纳答案by Austin
According to pip documentation at
根据 pip 文档在
http://pip.readthedocs.org/en/stable/user_guide/#configuration
http://pip.readthedocs.org/en/stable/user_guide/#configuration
You will need to specify the default install location within a pip.inifile, which, also according to the website above is usually located as follows
您需要在pip.ini文件中指定默认安装位置,根据上面的网站,该文件通常位于如下位置
On Unix and Mac OS X the configuration file is: $HOME/.pip/pip.conf
On Windows, the configuration file is: %HOME%\pip\pip.ini
在 Unix 和 Mac OS X 上,配置文件是:$HOME/.pip/pip.conf
在 Windows 上,配置文件为:%HOME%\pip\pip.ini
The %HOME%is located in C:\Users\Bob
on windows assumingyour name is Bob
在%HOME%位于C:\Users\Bob
在Windows假设你的名字是鲍勃
On linux the $HOME
directory can be located by using cd ~
在 linux 上,$HOME
可以通过使用来定位目录cd ~
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.ini
当您找到 pip 目录时,您可能必须创建该文件。在您的pip.ini
或pip.config
您将需要放置(假设您在 Windows 上)类似的东西
[global]
target=C:\Users\Bob\Desktop
Except that you would replace C:\Users\Bob\Desktop
with whatever path you desire. If you are on Linuxyou would replace it with something like /usr/local/your/path
除了你会用C:\Users\Bob\Desktop
你想要的任何路径替换。如果你在Linux 上,你会用类似的东西替换它/usr/local/your/path
After saving the command would then be
保存命令后,然后
pip install pandas
However, the program you install might assume it will be installed in a certain directory and might not work as a result of being installed elsewhere.
但是,您安装的程序可能会假定它会安装在某个目录中,并且可能由于安装在其他地方而无法运行。
回答by barbolo
You can set the following environment variable:
您可以设置以下环境变量:
PIP_TARGET=/path/to/pip/dir
https://pip.pypa.io/en/stable/user_guide/#environment-variables
https://pip.pypa.io/en/stable/user_guide/#environment-variables