如何更改pip的默认安装位置

时间:2022-09-21 22:41:18

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,但我遇到了一些麻烦。我刚刚运行了成功下载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 permanently changing the default location.

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

2 个解决方案

#1


24  

According to pip documentation at

根据pip文档

http://pip.readthedocs.org/en/stable/user_guide/#configuration

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

您需要在pip.ini文件中指定默认安装位置,这也是根据上面的网站通常如下所示

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

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

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

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

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

假设您的名字是Bob,%HOME%位于Windows上的C:\ Users \ Bob中

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

在linux上,可以使用cd~找到$ HOME目录

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\Bob\Desktop

Except that you would replace C:\Users\Bob\Desktop with whatever path you desire. If you are on Linux you 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.

但是,您安装的程序可能会认为它将安装在某个目录中,并且可能因为安装在其他位置而无法运行。

#2


13  

You can set the following environment variable:

您可以设置以下环境变量:

PIP_TARGET=/path/to/pip/dir

https://pip.pypa.io/en/stable/user_guide/#environment-variables

#1


24  

According to pip documentation at

根据pip文档

http://pip.readthedocs.org/en/stable/user_guide/#configuration

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

您需要在pip.ini文件中指定默认安装位置,这也是根据上面的网站通常如下所示

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

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

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

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

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

假设您的名字是Bob,%HOME%位于Windows上的C:\ Users \ Bob中

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

在linux上,可以使用cd~找到$ HOME目录

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\Bob\Desktop

Except that you would replace C:\Users\Bob\Desktop with whatever path you desire. If you are on Linux you 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.

但是,您安装的程序可能会认为它将安装在某个目录中,并且可能因为安装在其他位置而无法运行。

#2


13  

You can set the following environment variable:

您可以设置以下环境变量:

PIP_TARGET=/path/to/pip/dir

https://pip.pypa.io/en/stable/user_guide/#environment-variables