Coder Perfect

Pip packages are installed in the $HOME folder.

Problem

Is that even possible? Install the python packages in my $HOME folder when installing pip. (For example, instead of installing mercurial on /usr/local, I’d like to install it under $HOME.)

I’m on a Mac, and I was just thinking about how instead of “polluting” my /usr/local, I could utilize my $HOME instead.

This is what PEP370 is all about. Is it enough to simply create a /.local and run pip install package to have these packages installed only in my $HOME folder?

Asked by Somebody still uses you MS-DOS

Solution #1

You don’t have to utilize a virtualenv if you don’t want to. Passing the PEP370 —user parameter to the setup.py script is the key. One method to accomplish it with the latest version of pip is to:

pip install --user mercurial

The hg script should be installed in $HOME/.local/bin/hg, and the remainder of the hg package should be installed in $HOME/.local/lib/pythonx.y/site-packages/.

It’s worth noting that the above is correct for Python 2.6. There has been some debate among the Python core developers over the proper directory location for PEP370-style user installations on Mac OS X. On Mac OS X, the location of Python 2.7 and 3.2 was changed from $HOME/.local to $HOME/Library/Python. This could change in a later version. For now, the above locations will be $HOME/Library/Python/x.y/bin/hg and $HOME/Library/Python/x.y/lib/python/site-packages on Python 2.7 (and 3.2 if hg were available on Python 3).

Answered by Ned Deily

Solution #2

At your HOME directory, I would use virtualenv.

$ sudo easy_install -U virtualenv
$ cd ~
$ virtualenv .
$ bin/pip ...

You could then add /bin to your PATH in /.(login|profile|bash profile), whatever is appropriate for your shell, and pip|python|easy install would be utilized by default.

Answered by Ross Patterson

Solution #3

The -t option (—target) can be used to define the destination directory. For further information, see pip install —help. You’ll need to use the following command:

pip install -t path_to_your_home package-name

For instance, in order to install mxnet in my $HOME directory, I type:

pip install -t /home/foivos/ mxnet

Answered by Foivos

Solution #4

Yes

It is possible to install pip packages to $HOME rather than /usr/local/lib/, however this is not recommended.

mkdir ˜/.local # then
pip install package 

is not enough.

You need

pip install package --user

as well as the packages are installed

/home/user/.local/lib/python3.x/site-packages

Answered by Timo

Post is based on https://stackoverflow.com/questions/7143077/installing-pip-packages-to-home-folder