using pip to install packages locally in spite of satisfied global requirements

早过忘川 提交于 2019-12-07 04:24:52

问题


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:


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.



来源:https://stackoverflow.com/questions/16269101/using-pip-to-install-packages-locally-in-spite-of-satisfied-global-requirements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!