22

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

Oftentimes, the package installed by pip won't be found by my jupyter notebook and that's why I want to change the path.

I appreciate your help. Other solutions for correctly installing packages are welcome.

xtt
  • 857
  • 1
  • 8
  • 24

2 Answers2

28

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

-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.ini configuration file. See this for detail: pip install path

On Unix and Mac OS X the configuration file is:

$HOME/.pip/pip.conf

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

 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

[global]
target=C:\Users\<username>\Desktop
Community
  • 1
  • 1
Ijaz Ahmad
  • 11,198
  • 9
  • 53
  • 73
  • 6
    Sorry, but I don't have .pip under then folder you mentioned in windows – cloudscomputes Jan 23 '19 at 07:39
  • 2
    On my Ubuntu 18.04 pip's configuration file located on: "~/.config/pip/pip.conf" (for user), "/etc/pip.conf" (global config). If you does not know where is pip.conf should be located on your system you can use command: "python -m pip config [--global | --user | --site] [--editor ] edit". example: "python3 -m pip config --user --editor gedit edit". This command for modern pip only. It works on pip 20, but on pip 9 it does not. – sir__finley Feb 10 '20 at 11:17
  • 1
    Using `--target` like this is not a good idea, as pip doesn't treat the destination directory as a "system site location". In the OP's case, it looks like they are trying to get the pip from one Python installation to install into a different (Anaconda) install. This is not supported by pip - you should use the pip that is installed with your Python environment to install packages in that environment. – Paul Moore Jan 03 '22 at 19:24
  • I agree with @PaulMoore in the context of the question title, this might be a good choice. Considering the questions body (two different python installations) this is not the correct approach – FlyingTeller Aug 17 '22 at 13:06
4

On macOS go to /usr/local/bin/.

Remove the link to pip:

rm /usr/local/bin/pip

Create the new link pointing to the new installation:

sudo ln -s /new path /usr/local/bin/pip
anothernode
  • 5,100
  • 13
  • 43
  • 62