尽管满足了全球要求,仍可以使用pip在本地安装软件包 [英] using pip to install packages locally in spite of satisfied global requirements
问题描述
我正在尝试使用pip在~/.local
中本地安装软件包.问题是该软件包(较旧的版本)已在系统上全局可用.即使我的PYTHONPATH
中的全局python软件包目录不是 ,pip仍然拒绝安装,以为满足软件包要求.这类似于此处描述的问题,除了我没有使用sudo
之外,因此该解决方案不适用: pip-要求已经满足?
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?
如果我这样做:
pip install --user numpy
它说:
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
但是,/usr/local/lib/...
不在我的PYTHONPATH
中. PYTHONPATH
中唯一的东西是~/.local
.
However, /usr/local/lib/...
is not in my PYTHONPATH
. The only thing in PYTHONPATH
is ~/.local
.
如果我尝试这样做:
pip install --user --upgrade numpy
它会下载numpy并进行编译,然后认为我正在进行全局安装,尽管带有--user 标志,但我得到了:
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'
如何解决?我不确定为什么在传递--user
标志时,它会尝试执行任何需要全局权限的事情.
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.
是否有一种方法可以告诉pip仅使用~/.local
并忽略系统上的其他所有内容? (我不想使用virtualenv!在这里是不必要的,我不想只有一个环境.)
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.)
推荐答案
引用 Marcus Smith(点子的维护者):
Citing Marcus Smith (maintainer of pip):
如果您认为全球站点已过时,并且想要最新的站点 用户站点,然后使用:
pip install --upgrade --user SomePackage
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
由于(...),该软件包(较旧的版本)已在系统上全局可用,因此您必须按照Marcus的说明使用--upgrade
选项.
卸载系统numpy软件包可能是您所使用的pip版本(1.2.1)中的错误.尝试使用当前版本,因为与--user
选项相关的许多问题在1.3和1.4版本中已解决
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
编辑
Marcus Smith 在他后来的评论中指向特定问题:
Marcus Smith points to specific issue in his later comment:
pip 1.3具有#705,这对于使用--user和--upgrade至关重要 在一起.
pip 1.3 has #705 , which is critical for using --user and --upgrade together.
这篇关于尽管满足了全球要求,仍可以使用pip在本地安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!