20

I'm trying to install packages locally with pip. It used to work with --user but now when I try it, it finds the version of the package in /usr/local/lib/ and then does not install it locally. Normally it would install things in ~/.local but now it just checks the system-wide dir for the package and if it's there, it does not install it (which is not what I want) and if it's not there, it tries to install it in /usr/local/lib which I do not have write permissions at. Eg:

$ pip install --user rpy2
Requirement already satisfied (use --upgrade to upgrade): rpy2 in /usr/local/lib/python2.7/dist-packages/

How can I make pip install --user always go to ~/.local and not a system-wide directory?

  • well it says that the it "Requirement" is satisfied and it tells you to use the --upgrade option, have you tried using it? – PurityLake Mar 14 '13 at 20:08
  • @PurityLake: yes, that doesn't change anything –  Mar 15 '13 at 12:44
  • 3
    "software tools commonly used by programmers", like `pip`, are on topic. Voted to reopen. – Mechanical snail Aug 04 '13 at 01:45
  • I agree this should be reopened. A similar question is http://stackoverflow.com/questions/16269101/using-pip-to-install-packages-locally-in-spite-of-satisfied-global-requirements?rq=1 – RNA Nov 21 '13 at 01:46
  • This may not be a fix, but this could save you some time. Try to use virtualenv where you want an installation different from system wide installation – user2390183 Nov 30 '13 at 18:14
  • I think my answer provides solution – could you please check it out? – Piotr Dobrogost Nov 07 '14 at 09:32

3 Answers3

23

Citing Marcus Smith (maintainer of pip):

If you think the global site is out of date, and want the latest in the user site, then use:
pip install --upgrade --user SomePackage

If the global site is up to date, and you really just want the same thing duplicated in --user, then use:
pip install --ignore-installed --user SomePackage (which works correctly now after the merge of #1352, which is to be released in v1.5)

How can I make pip install --user always go to ~/.local and not a system-wide directory?

Use both --upgrade and --ignore-installed arguments.

Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
  • 1
    Thanks for mentioning pip bugs. The only thing I'm missing is to combine --prefix with --user, see http://stackoverflow.com/questions/24420125/python-change-user-site-directory-or-install-setup-py-prefix-with-user – rudimeier Jun 26 '14 at 05:35
4

According to the pip documentation, that syntax is correct, but requires Python 2.6.

User Installs

With Python 2.6 came the “user scheme” for installation, which means that all Python distributions support an alternative install location that is specific to a user. The default location for each OS is explained in the python documentation for the site.USER_BASE variable. This mode of installation can be turned on by specifying the –user option to pip install.

Moreover, the “user scheme” can be customized by setting the PYTHONUSERBASE environment variable, which updates the value of site.USER_BASE.

To install “SomePackage” into an environment with site.USER_BASE customized to ‘/myappenv’, do the following:

export PYTHONUSERBASE=/myappenv 
pip install --user SomePackage



So the following entry should work for you:

export PYTHONUSERBASE=~/.local
pip install --user rpy2
JamCon
  • 2,313
  • 2
  • 25
  • 34
  • The pip documentation is located at: [pip cookbook](http://www.pip-installer.org/en/latest/cookbook.html) – JamCon Mar 14 '13 at 20:30
  • 1
    MagicalPony: Did not know about that, thanks. But setting PYTHONUSERBASE does not work - it's still looking in `/usr/local/lib/` –  Mar 15 '13 at 12:45
  • `pip install --user --force-reinstall --upgrade jinja2` can install to `~/.local/` dir. – RNA Nov 21 '13 at 01:35
  • This may not be a fix, but this could save you some time. Try to use virtualenv where you want an installation different from system wide installation – user2390183 Nov 30 '13 at 18:20
0

installing any package using user command

for upgrading pip :

python -m pip install --upgrade --user pip
taras
  • 6,566
  • 10
  • 39
  • 50
Bachi
  • 1
  • 2