如何更改 pip 的默认安装位置 [英] How to change default install location for pip

查看:142
本文介绍了如何更改 pip 的默认安装位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 pip 安装 Pandas,但遇到了一些麻烦.我刚刚运行 sudo pip install pandas 成功下载了熊猫.但是,它没有下载到我想要的位置.这是我在使用 pip show pandas 时看到的:

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:

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

这样就安装好了.但是当我创建一个新的 Python 项目并在 System Libs/lib/python 下搜索 pandas 时,我很困惑,因为它没有出现.但是,我过去下载的一些其他软件包确实出现了,因此我尝试查看它们的位置.运行 pip show 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:

---
Name: numpy
Version: 1.6.2
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requires: 

位于完全不同的目录中.为了确认我的错误,我运行 pip install pyquery 来查看它会下载到哪里,然后得到:

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:

Name: pyquery
Version: 1.2.8
Location: /Library/Python/2.7/site-packages
Requires: lxml, cssselect

所以和熊猫一样的地方...

So the same place as pandas...

如何更改 pip 的默认下载位置,以便将这些包下载到 numpy 所在的同一位置?

How do I change the default download location for pip so that these packages are downloaded to the same location that numpy is in?

注意:我在搜索解决方案时看到了一些类似的问题,但我没有看到任何提到永久更改默认位置的内容.

Note: There were a few similar questions that I saw when searching for a solution, but I didn't see anything that mentioned permanently changing the default location.

推荐答案

根据 pip 文档在

http://pip.readthedocs.org/en/stable/user_guide/#配置

您需要在 pip.ini 文件中指定默认安装位置,根据上面的网站,该文件通常位于以下位置

You will need to specify the default install location within a pip.ini file, which, also according to the website above is usually located as follows

在 Unix 和 Mac OS X 上,配置文件是:$HOME/.pip/pip.conf

On Unix and Mac OS X the configuration file is: $HOME/.pip/pip.conf

在 Windows 上,配置文件为:%HOME%pippip.ini

On Windows, the configuration file is: %HOME%pippip.ini

%HOME% 位于 Windows 上的 C:UsersBob 假设您的名字是 Bob>

The %HOME% is located in C:UsersBob on windows assuming your name is Bob

在 linux 上,$HOME 目录可以通过使用 cd ~

On linux the $HOME directory can be located by using cd ~

当您找到 pip 目录时,您可能需要创建 pip.ini 文件.在您的 pip.inipip.config 中,您将需要放置(假设您在 Windows 上)类似

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

[global]
target=C:UsersBobDesktop

除非您将C:UsersBobDesktop 替换为您想要的任何路径.如果您使用的是 Linux,您可以将其替换为 /usr/local/your/path

Except that you would replace C:UsersBobDesktop with whatever path you desire. If you are on Linux you would replace it with something like /usr/local/your/path

保存命令后

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.

这篇关于如何更改 pip 的默认安装位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆