Installing pip packages to $HOME folder
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2
--
Chapters
00:00 Installing Pip Packages To $Home Folder
00:38 Answer 1 Score 22
01:00 Accepted Answer Score 477
02:13 Answer 3 Score 22
02:37 Answer 4 Score 0
03:22 Thank you
--
Full question
https://stackoverflow.com/questions/7143...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pip
#avk47
ACCEPTED ANSWER
Score 477
While you can use a virtualenv, you don't need to.  The trick is passing the PEP370 --user argument to the setup.py script.  With the latest version of pip, one way to do it is:
pip install --user mercurial
This should result in the hg script being installed in $HOME/.local/bin/hg and the rest of the hg package in $HOME/.local/lib/pythonx.y/site-packages/.
Note, that the above is true for Python 2.6.  There has been a bit of controversy among the Python core developers about what is the appropriate directory location on Mac OS X for PEP370-style user installations.  In Python 2.7 and 3.2, the location on Mac OS X was changed from $HOME/.local to $HOME/Library/Python.  This might change in a future release.  But, for now, on 2.7 (and 3.2, if hg were supported on Python 3), the above locations will be $HOME/Library/Python/x.y/bin/hg and $HOME/Library/Python/x.y/lib/python/site-packages.
ANSWER 2
Score 22
I would use virtualenv at your HOME directory.
$ sudo easy_install -U virtualenv
$ cd ~
$ virtualenv .
$ bin/pip ...
You could then also alter ~/.(login|profile|bash_profile), whichever is right for your shell to add ~/bin to your PATH and then that pip|python|easy_install would be the one used by default.
ANSWER 3
Score 22
You can specify the -t option (--target) to specify the destination directory. See pip install --help for detailed information. This is the command you need: 
pip install -t path_to_your_home package-name
for example, for installing say mxnet, in my $HOME directory, I type: 
pip install -t /home/foivos/ mxnet
ANSWER 4
Score 0
Short answer to your two questions grabbed from the other answers
One
Yes
it is possible installing pip packages to $HOME instead of /usr/local/lib/, but
Two
mkdir ˜/.local # then
pip install package 
is not enough.
You need
pip install package --user
and the packages get installed to
/home/user/.local/lib/python3.x/site-packages
Exception when you do not need --user
- if you are not root user
 - On 
Debiantogether withWsl- Windows Subsystem Linux no notice - On Ubuntu 20.04 notice 
default to user installation because normal site-packages not writeable- default config is/usr/libnot writeable for other users except root