using pip to install packages locally in spite of

2019-05-01 10:24发布

I am trying to use pip to install a package locally in ~/.local. The problem is that the package (in an older version) is already available globally on the system. Even though the global python packages directory is not in my PYTHONPATH, pip still refuses to install, thinking that the package requirement is satisfied. This is similar to the issue described here, except I am not using sudo so the solution does not apply: pip - Requirement already satisfied?

If I do:

pip install --user numpy

It says:

Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/local/lib/python2.7/dist-packages/numpy-1.6.2-py2.7-linux-x86_64.egg

However, /usr/local/lib/... is not in my PYTHONPATH. The only thing in PYTHONPATH is ~/.local.

If I try to do:

pip install --user --upgrade numpy

It downloads numpy and compiles it, and then thinks I am doing a global install in spite of the --user flag and I get:

Installing collected packages: numpy
  Found existing installation: numpy 1.6.2
    Uninstalling numpy:
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip-1.2.1-py2.7.egg/pip/basecommand.py", line 107, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.2.1-py2.7.egg/pip/commands/install.py", line 261, in run
    requirement_set.install(install_options, global_options)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 1162, in install
    requirement.uninstall(auto_confirm=True)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 495, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 1492, in remove
    renames(path, new_path)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.2.1-py2.7.egg/pip/util.py", line 273, in renames
    shutil.move(old, new)
  File "/usr/lib/python2.7/shutil.py", line 300, in move
    os.unlink(src)
OSError: [Errno 13] Permission denied: '/usr/bin/f2py'

How can this be fixed? I'm not sure why it tries to do anything that requires global permissions when it's passed the --user flag.

Is there a way to tell pip to just use ~/.local and ignore everything else on the system? (I don't want to use virtualenv! It's unnecessary here, I don't want multiple environments, just one.)

1条回答
狗以群分
2楼-- · 2019-05-01 10:48

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

Because (...) the package (in an older version) is already available globally on the system you have to use --upgrade option as per above Marcus' remark. Uninstalling system numpy package is probably a bug in the version of pip you use (1.2.1). Try current version as many issues related to --user option were fixed in versions 1.3 and 1.4

EDIT

Marcus Smith points to specific issue in his later comment:

pip 1.3 has #705 , which is critical for using --user and --upgrade together.

查看更多
登录 后发表回答