Python 在 Ubuntu 12.04 上升级到 numpy 1.8.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19839488/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:46:12  来源:igfitidea点击:

Upgrade to numpy 1.8.0 on Ubuntu 12.04

pythonubuntunumpyinstallationupgrade

提问by Gabriel

I'm running Ubuntu 12.04 which comes by default with NumPy 1.6.0(I have, actually had, Python 2.7.3installed). As a result of the answer to this question polyfit() got an unexpected keyword argument 'w', I need to upgrade it.

我运行Ubuntu 12.04自带其默认使用NumPy 1.6.0(我有,其实Python 2.7.3安装)。由于对这个问题的回答polyfit() 得到了一个意外的关键字参数 'w',我需要升级它。

I downloaded the .tar.gzpackage for the version 1.8.0from here, unpacked it, moved inside the folder and run the commands:

我从这里下载了.tar.gz该版本的包,解压它,移动到文件夹内并运行命令:1.8.0

python setup.py build --fcompiler=gnu95
python setup.py install --user

as described in the user guideand in this question: Building NumPy 1.7.1 on Ubuntu.

用户指南和此问题中所述:在 Ubuntu 上构建 NumPy 1.7.1

This resulted in NumPyno longer loading in Spyder, which now shows the error:

这导致NumPy不再加载 in Spyder,现在显示错误:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/spyderlib/scientific_startup.py", line 16, in <module>
    from pylab import *  #analysis:ignore
  File "/usr/local/lib/python2.7/dist-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 165, in <module>
    from matplotlib.rcsetup import (defaultParams,
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/rcsetup.py", line 20, in <module>
    from matplotlib.colors import is_color_like
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/colors.py", line 52, in <module>
    import numpy as np
  File "/home/gabriel/.local/lib/python2.7/site-packages/numpy/__init__.py", line 153, in <module>
    from . import add_newdocs
  File "/home/gabriel/.local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/gabriel/.local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/home/gabriel/.local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/home/gabriel/.local/lib/python2.7/site-packages/numpy/core/__init__.py", line 6, in <module>
    from . import multiarray
ImportError: /home/gabriel/.local/lib/python2.7/site-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS2_FromUnicode

upon loading it. The same happened when I tried with version 1.7.1.

加载后。当我尝试使用 version 时发生了同样的情况1.7.1

I tried removing numpywith:

我尝试删除numpy

sudo apt-get remove python-numpy

which also removed matplotliband scipy. So then I tried reinstalling them with:

这也删除了matplotlibscipy。然后我尝试重新安装它们:

sudo apt-get install python-numpy python-scipy python-matplotlib

but this fails with the error:

但这失败并出现错误:

    from sre_constants import *
  File "/usr/local/lib/python2.7/sre_constants.py", line 18, in <module>
    from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT

Now I'm left with no running python and I don't even know how to go back to the previous stable version. So the question: can I install at least version 1.7.1in my system and if not, how do I go back to a working 1.6.0version? Thanks.

现在我没有运行 python,我什至不知道如何回到以前的稳定版本。所以问题是:我可以1.7.1在我的系统中安装至少一个版本,如果没有,我如何回到工作1.6.0版本?谢谢。

采纳答案by TheGrimmScientist

sudo pip install numpy --upgrade

will do the same thing with slightly less effort.

会以更少的努力做同样的事情。

回答by Gabriel

Ok, so I tried:

好的,所以我试过:

pip uninstall numpy

which returned:

返回:

Successfully uninstalled numpy

So then I did:

然后我做了:

pip install numpy

but it said:

但它说:

Requirement already satisfied (use --upgrade to upgrade): numpy in /home/gabriel/.local/lib/python2.7/site-packages
Cleaning up...

so apparently it was still there. I removed the contents of that folder and then I simply did:

所以显然它还在那里。我删除了该文件夹的内容,然后我只是做了:

sudo pip install numpy

This worked like freaking magic. Now I have NumPy 1.8.0, SciPy 0.12.0, Matplotlib 1.2.1installed and everything is running like it should.

这就像该死的魔法。现在我已经NumPy 1.8.0, SciPy 0.12.0, Matplotlib 1.2.1安装了,一切都像它应该的那样运行。