如何在Python shell中导入NumPy

时间:2012-08-10 17:33:37

标签: python numpy

我尝试在Python中导入NumPy,但它没有成功:

>>> import numpy as np
    x=np.array([[7,8,5],[3,5,7]],np.int32)

   Traceback (most recent call last):
   File "<pyshell#3>", line 1, in <module>
   import numpy as np
   File "C:\Python27\lib\numpy\__init__.py", line 127, in <module>
   raise ImportError(msg)
   ImportError: Error importing numpy: you should not try to import numpy from
   its source directory; please exit the numpy source tree, and relaunch
   your Python interpreter from there.

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:19)

该信息相当不言自明;调用Python时,您的工作目录不应该是NumPy源目录;应该安装NumPy,你的工作目录应该是它所在的目录。

答案 1 :(得分:1)

Debian / Ubuntu:

aptitude install python-numpy

在Windows上,下载安装程序:

http://sourceforge.net/projects/numpy/files/NumPy/

在其他系统上,下载tar.gz并运行以下命令:

$ tar xfz numpy-n.m.tar.gz
$ cd numpy-n.m
$ python setup.py install