Python 为什么 pip 不更新我的 numpy 和 scipy?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26390895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why isn't pip updating my numpy and scipy?
提问by Spacey
My problem is that pip won't update my Python Packages, even though there are no errors.
我的问题是 pip 不会更新我的 Python 包,即使没有错误。
It is similar to this one, but I am still now sure what to do. Basically, ALL my packages for python appear to be ridiculously outdated, even after updating everything via pip. Here are the details:
它与此类似,但我现在仍然确定该怎么做。基本上,即使在通过 pip 更新所有内容之后,我的所有 python 包似乎都过时了。以下是详细信息:
- I am using pip, version 1.5.6.
- I am using Python, version 2.7.5
- I am on a Mac OSX, verion 10.9.5.
- 我正在使用 pip,版本 1.5.6。
- 我正在使用 Python,版本 2.7.5
- 我在 Mac OSX 上,版本 10.9.5。
Using that, I have:
使用它,我有:
- My numpy version is 1.6.2.
- My scipy version is 0.11.0.
- My matplotlib version is 1.1.1.
- 我的 numpy 版本是 1.6.2。
- 我的 scipy 版本是 0.11.0。
- 我的 matplotlib 版本是 1.1.1。
Even after I try:
即使在我尝试之后:
sudo pip uninstall numpy
Followed by:
其次是:
sudo pip install numpy
They both complete successfully, but when I go into python and check the version of numpy, it is still the old one. (As are all the other packages).
它们都成功完成,但是当我进入 python 并检查 numpy 的版本时,它仍然是旧的。(与所有其他包一样)。
Not sure what is going on here?... How can this be fixed? P.S. I am new to this, so I might need explicit instructions. Thanks. Also, if anyone wants, I can provide a screenshot of pip as it is installing numpy.
不确定这里发生了什么?...如何解决?PS我是新手,所以我可能需要明确的说明。谢谢。另外,如果有人愿意,我可以提供 pip 的屏幕截图,因为它正在安装 numpy。
EDIT:
编辑:
Commands I ran as per the comments:
我按照评论运行的命令:
$which -a pip
/usr/local/bin/pip
$ head -1 $(which pip)
#!/usr/bin/python
$ which -a python
/usr/bin/python
回答by abarnert
In OS X 10.9, Apple's Python comes with a bunch of pre-installed extra packages, in a directory named /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python. Including numpy.
在 OS X 10.9 中,Apple 的 Python 在名为/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python. 包括numpy.
And the way they're installed (as if by using easy_installwith an ancient pre-0.7 version of setuptools, but not into either of the normal easy_installdestinations), pipdoesn't know anything about them.
并且它们的安装方式(好像是使用easy_install0.7 之前的古老版本setuptools,但没有安装到任何一个正常easy_install目的地),pip对它们一无所知。
So, what happens is that sudo pip install numpyinstalls a separate copy of numpyinto '/Library/Python/2.7/site-packages'—but in your sys.path, the Extrasdirectory comes before the site-packagesdirectory, so import numpystill finds Apple's copy. I'm not sure why that is, but it's probably not something you want to monkey with.
因此,发生的情况是sudo pip install numpy安装了一个单独的numpyinto '/Library/Python/2.7/site-packages'— 但在您的 中sys.path,该Extras目录位于该目录之前site-packages,因此import numpy仍然可以找到 Apple 的副本。我不确定为什么会这样,但这可能不是您想要玩弄的东西。
So, how do you fix this?
那么,你如何解决这个问题?
The two best solutions are:
两个最好的解决方案是:
Use
virtualenv, and install yournumpyand friends into a virtual environment, instead of system-wide. This has the downside that you have to learn how to usevirtualenv—but that's definitely worth doing at some point, and if you have the time to learn it now, go for it.Upgrade to Python 3.x, either from a python.org installer or via Homebrew. Python 3.4 or later comes with
pip, and doesn't come with anypip-unfriendly pre-installed packages. And, unlike installing a separate 2.7, it doesn't interfere with Apple's Python at all;python3andpython,pip3andpip, etc., will all be separate programs, and you don't have to learn anything about how PATH works or any of that. This has the downside that you have to learn Python 3.x, which has some major changes, so again, a bit of a learning curve, but again, definitely worth doing at some point.
使用
virtualenv,并将您numpy和朋友安装到虚拟环境中,而不是系统范围内。这有一个缺点,你必须学习如何使用virtualenv——但在某些时候这绝对值得做,如果你现在有时间学习,那就去做吧。从 python.org 安装程序或通过 Homebrew 升级到 Python 3.x。Python 3.4 或更高版本带有
pip,并且不带有任何pip不友好的预安装包。而且,与安装单独的 2.7 不同,它根本不会干扰 Apple 的 Python;python3和python、pip3和pip等都将是单独的程序,您无需了解有关 PATH 的工作原理或任何其他内容的任何信息。这有一个缺点,你必须学习 Python 3.x,它有一些重大变化,所以再一次,有点学习曲线,但同样,在某些时候绝对值得做。
Assuming neither of those is possible, I think the simplest option is to use easy_installinstead of pip, for the packages you want to install newer versions of any of Apple's "extras". You can get a full list of those by looking at what's in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python. When you upgrade numpy, you probably also want to upgrade scipyand matplotlib; I think everything else there is unrelated. (You can of course upgrade PyObjCor dateutilor anything else you care about there, but you don't have to.)
假设这两个都不可能,我认为最简单的选择是使用 ,easy_install而不是pip, 对于要安装任何Apple“附加功能”的较新版本的软件包。您可以通过查看/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python. 升级时numpy,您可能还想升级scipy和matplotlib;我认为其他一切都无关紧要。(您当然可以在那里升级PyObjC或dateutil其他任何您关心的东西,但您不必这样做。)
This isn't an ideal solution; there are a lot of reasons easy_installis inferior to pip(e.g., not having an uninstaller, so you're going to have to remember where that /Library/blah/blahpath is (or find it again by printout out sys.pathfrom inside Python). I wouldn't normally suggest easy_installfor anything except readlineand pipitself (and then only with Apple's Python). But in this case, I think it's simpler than the other alternatives.
这不是一个理想的解决方案;有很多的原因,easy_install不如pip(例如,没有卸载程序,所以你不得不记住的是/Library/blah/blah路径(或打印出来再次找到它sys.path从内Python)的。通常我不会建议easy_install对除了readlineandpip本身之外的任何东西(然后只使用 Apple 的 Python)。但在这种情况下,我认为它比其他替代方案更简单。
回答by Eddie
Rename the numpy and scipy versions installed by Apple in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/ so it starts using the newer versions installed by Pip.
重命名 Apple 在 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/ 中安装的 numpy 和 scipy 版本,以便它开始使用 Pip 安装的较新版本。
回答by cag51
Old question, but I found it when trying to solve this issue, will post my solution.
老问题,但我在尝试解决此问题时发现它,将发布我的解决方案。
I found @abarnert's diagnosis to be correct and helpful, but I don't like any of the solutions: I really want to upgrade the default version of numpy. The challenge is that the directory these guys are in (which @abarnert mentioned) cannot be touched even by sudo, as they are in this "wheel" group. In fact, if you go there and do sudo rm -rf blah, it will give you a permission denied error.
我发现@abarnert 的诊断是正确且有帮助的,但我不喜欢任何解决方案:我真的很想升级 numpy 的默认版本。挑战在于这些人所在的目录(@abernert 提到的)甚至无法触及sudo,因为他们在这个“轮子”组中。事实上,如果你去那里做sudo rm -rf blah,它会给你一个权限被拒绝的错误。
To get around this, we have to take drastic action:
为了解决这个问题,我们必须采取激烈的行动:
- Reboot the computer in recovery mode
- Find the terminal and type
csrutil disable - Reboot normally, then upgrade numpy with
pip2 install --user --upgrade numpy(and same for any other packages that have this problem) - Repeat steps a and b, this time changing "disable" to "enable"
- 以恢复模式重新启动计算机
- 找到终端并输入
csrutil disable - 正常重启,然后升级 numpy
pip2 install --user --upgrade numpy(对于有此问题的任何其他软件包也是如此) - 重复步骤 a 和 b,这次将“禁用”更改为“启用”
Note: "csrutil disable" is serious business that can destabilize your machine, I would use it only when absolutely necessary and re-enable it ASAP. But AFAIK it's the only way to upgrade Python packages in a wheel directory.
注意:“csrutil disable”是一个严重的问题,可能会破坏您的机器的稳定性,我只会在绝对必要时使用它并尽快重新启用它。但 AFAIK 这是在wheel 目录中升级Python 包的唯一方法。

