How to change default install location for pip

Question:

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

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: 

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…

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.

Asked By: weskpga

||

Answers:

According to pip documentation at

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

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

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

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

On linux the $HOME directory can be located by using 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

[global]
target=C:UsersBobDesktop

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

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.

Answered By: Austin

You can set the following environment variable:

PIP_TARGET=/path/to/pip/dir

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

Answered By: barbolo

Open Terminal and type:

pip config set global.target /Users/Bob/Library/Python/3.8/lib/python/site-packages

except instead of

/Users/Bob/Library/Python/3.8/lib/python/site-packages

you would use whatever directory you want.

Answered By: Jarrell Khoo

Follow these steps

  1. pip config set global.target D:site-packages to change install path

or py -m pip config --user --editor notepad edit

[global]
target = D:site-packages
  1. set environment variable to use download import xxx

    PIP_TARGET=site-packages
    PYTHONPATH=site-packages

3.pip config unset global.target, to upgrade pip py -m pip install --upgrade pip

Answered By: user15408191

@Austin’s answer is outdated, here for more up-to-date solution:

According to pip documentation at

https://pip.pypa.io/en/stable/topics/configuration/

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

Mac OS

$HOME/Library/Application Support/pip/pip.conf if directory $HOME/Library/Application Support/pip exists else $HOME/.config/pip/pip.conf.

The legacy “per-user” configuration file is also loaded, if it exists: $HOME/.pip/pip.conf.

The $HOME folder can be located by navigating to ~/ (cmd+shift+G in Finder; cmd+shift+. to show hidden files).

Windows

%APPDATA%pippip.ini

The legacy “per-user” configuration file is also loaded, if it exists: %HOME%pippip.ini

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

Unix

$HOME/.config/pip/pip.conf, which respects the XDG_CONFIG_HOME environment variable.

The legacy “per-user” configuration file is also loaded, if it exists: $HOME/.pip/pip.conf.

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

You may have to create the configuration file when you find your pip directory. Put something like

[global]
target = /Library/Frameworks/Python.framework/Versions/Current/lib/python3.10/site-packages/

if you are on a Mac. Except that you would replace /Library/Frameworks/Python.framework/Versions/Current/lib/python3.10/site-packages/ with whatever path you desire. If you are on Linux you would replace it with something like /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.

Please note that

pip3 install pandas

might be the solution if your packages gets installed in the Python2 folder vs Python3.

Answered By: Marcus Lauritsen
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.