我正在尝试使用 pip 在 ~/.local
中本地安装一个包。问题是该包(在旧版本中)已经在系统上全局可用。即使全局 python 包目录在我的 PYTHONPATH
中不,pip 仍然拒绝安装,认为包要求已满足。这与此处描述的问题类似,只是我没有使用 sudo
,因此解决方案不适用: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
。
如果我尝试这样做:
pip install --user --upgrade numpy
它下载 numpy 并编译它,然后认为我正在执行全局安装尽管 --user 标志并且我得到:
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
标志时会尝试执行任何需要全局权限的操作。
有没有办法告诉 pip 只使用 ~/.local
而忽略系统上的所有其他内容? (我不想用virtualenv!这里没必要,我不要多个环境,就一个。)
最佳答案
Citing Marcus Smith(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
因为 (...) 软件包(在旧版本中)已经在系统上全局可用 你必须按照上面的 Marcus 使用 --upgrade
选项' 评论。
卸载系统 numpy 包可能是您使用的 pip 版本 (1.2.1) 中的错误。尝试当前版本,因为许多与 --user
选项相关的问题已在 1.3 和 1.4 版本中修复
编辑
马库斯·史密斯 points在他后来的评论中针对具体问题:
pip 1.3 has #705 , which is critical for using --user and --upgrade together.
关于python - 尽管满足了全局要求,但仍使用 pip 在本地安装软件包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16269101/