根据Scipy网站的说法,在Ubuntu 11.10中,numpy和scipy预先打包,所以我做的是:
apt-get install python2.7
apt-get install python-numpy
apt-get install python-scipy
然后我尝试在Python中调用numpy,但得到一个错误:
ImportError: cannot import name datetime_data.
为什么会这样?附加完整的错误消息。
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 8, in <module>
import numerictypes as nt
File "/usr/local/lib/python2.7/dist-packages/numpy/core/numerictypes.py", line 92, in <module>
from numpy.core.multiarray import typeinfo, ndarray, array, \
ImportError: cannot import name datetime_data
答案 0 :(得分:3)
看起来你在/usr/local/lib/python2.7/dist-packages中有一个破坏的numpy安装,包管理器将numpy安装到/usr/lib/pyshared/python2.7
你应该删除破碎的numpy
$ sudo rm -rf /usr/local/lib/python2.7/dist-packages/numpy
然后您使用apt-get
安装的numpy应按预期工作。
答案 1 :(得分:0)
升级我的numpy版本后,我遇到了类似的问题。我解决了它重新安装和删除numpy lib文件夹(对于你的python版本)
sudo apt-get remove python-numpy
sudo rm -r /usr/local/lib/pythonX.X/dist-packages/numpy
sudo apt-get install python-numpy
(或从任何numpy包中安装新的numpy版本)