5 python numpy pip setuptools pythonpath
我正在尝试使用pip在本地安装软件包~/.local.问题是程序包(旧版本)已在系统上全局可用.即使全局python包目录不在我的中PYTHONPATH,pip仍然拒绝安装,认为满足包需求.这类似于这里所描述的问题,但我不使用sudo这样的解决方案并不适用:画中画-要求已经满足了吗?
如果我做:
pip install --user numpy
Run Code Online (Sandbox Code Playgroud)
它说:
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
Run Code Online (Sandbox Code Playgroud)
但是,/usr/local/lib/...不是我的PYTHONPATH.唯一的问题PYTHONPATH是~/.local.
如果我尝试做:
pip install --user --upgrade numpy
Run Code Online (Sandbox Code Playgroud)
它下载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'
Run Code Online (Sandbox Code Playgroud)
怎么解决这个问题?我不确定为什么它会在传递--user标志时尝试做任何需要全局权限的事情.
有没有办法告诉pip只是使用~/.local并忽略系统上的其他所有内容?(我不想使用virtualenv!这里没有必要,我不想要多个环境,只需要一个.)
引用Marcus Smith(pip 维护者)的话:
如果您认为全局站点已过时,并且想要用户站点中的最新内容,请使用:
pip install --upgrade --user SomePackage
因为(...)该软件包(在旧版本中)已经在系统上全局可用,所以您必须--upgrade按照上面 Marcus 的评论使用选项。卸载系统 numpy 包可能是您使用的 pip 版本(1.2.1)中的错误。尝试当前版本,因为许多与选项相关的问题--user已在版本 1.3 和 1.4 中修复
编辑
马库斯·史密斯在后来的评论中指出了具体问题:
pip 1.3 有 #705 ,这对于一起使用 --user 和 --upgrade 至关重要。