导入 numpy - 没有名为 multiarray 的模块

导入 numpy - 没有名为 multiarray 的模块

在 Ubuntu 12.04 64 位上,我安装了 python 2.7.3 和 numpy 1.6.2。

当我尝试导入 numpy 时,出现以下信息:

erelsgl@erel-biu:/host/Dropbox/ai/routes$ python
Python 2.7.3 (default, Nov 25 2012, 17:50:36) 
[GCC 4.6.3] 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/site-packages/numpy/__init__.py", line 137, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
ImportError: No module named multiarray

奇怪的是,这个问题并没有出现在我的另一台电脑上,它运行的是 Ubuntu 12.04 64 位。

更新:我删除了 numpy 的手动安装:

$ sudo rm -rf /usr/local/lib/python2.7/site-packages/numpy

然后使用 apt 重新安装:

$ sudo apt-get install python-numpy
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libblas3gf libgfortran3 liblapack3gf
Suggested packages:
  python-numpy-doc python-numpy-dbg python-nose python-dev gfortran
The following NEW packages will be installed:
  libblas3gf libgfortran3 liblapack3gf python-numpy
0 upgraded, 4 newly installed, 0 to remove and 115 not upgraded.
Need to get 6,918 kB of archives.
After this operation, 19.2 MB of additional disk space will be used.
Do you want to continue [Y/n]? 
Get:1 http://il.archive.ubuntu.com/ubuntu/ precise/main libgfortran3 amd64 4.6.3-1ubuntu5 [357 kB]
Get:2 http://il.archive.ubuntu.com/ubuntu/ precise/main libblas3gf amd64 1.2.20110419-2ubuntu1 [287 kB]
Get:3 http://il.archive.ubuntu.com/ubuntu/ precise/main liblapack3gf amd64 3.3.1-1 [4,424 kB]
Get:4 http://il.archive.ubuntu.com/ubuntu/ precise/main python-numpy amd64 1:1.6.1-6ubuntu1 [1,850 kB]
Fetched 6,918 kB in 0s (8,638 kB/s)     
Preconfiguring packages ...
Selecting previously unselected package libgfortran3.
(Reading database ... 80%
(Reading database ... 237799 files and directories currently installed.)
Unpacking libgfortran3 (from .../libgfortran3_4.6.3-1ubuntu5_amd64.deb) ...
Selecting previously unselected package libblas3gf.
Unpacking libblas3gf (from .../libblas3gf_1.2.20110419-2ubuntu1_amd64.deb) ...
Selecting previously unselected package liblapack3gf.
Unpacking liblapack3gf (from .../liblapack3gf_3.3.1-1_amd64.deb) ...
Selecting previously unselected package python-numpy.
Unpacking python-numpy (from .../python-numpy_1%3a1.6.1-6ubuntu1_amd64.deb) ...
Processing triggers for man-db ...
Setting up libgfortran3 (4.6.3-1ubuntu5) ...
Setting up libblas3gf (1.2.20110419-2ubuntu1) ...
update-alternatives: using /usr/lib/libblas/libblas.so.3gf to provide /usr/lib/libblas.so.3gf (libblas.so.3gf) in auto mode.
Setting up liblapack3gf (3.3.1-1) ...
update-alternatives: using /usr/lib/lapack/liblapack.so.3gf to provide /usr/lib/liblapack.so.3gf (liblapack.so.3gf) in auto mode.
Setting up python-numpy (1:1.6.1-6ubuntu1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

然后再次尝试,现在,numpy 根本无法被识别!

$ python
Python 2.7.3 (default, Nov 25 2012, 17:50:36) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy

答案1

我有同样的问题。我通过删除 dist 包中的 numpy 解决了这个问题

sudo rm -rf /usr/local/lib/python2.7/dist-packages/numpy

我没有再次安装它,它就成功了。我尝试导入 numpy 并测试,运行正常。我不知道为什么这对我有用。(也许是 numpy 安装文档的一部分,python 更早地检查了这个文件夹,你可以在 sys.path 中检查。)

答案2

事实上,它的存在/usr/local/lib意味着您已尝试“手动”安装 numpy,这可能是一个繁琐的过程。

最简单的方法是删除/usr/local/lib/python2.7/site-packages/numpy,并确保包python-numpy已安装(sudo apt-get install python-numpy)。

答案3

在尝试将 cv2 导入解释器之前,我花了两天时间研究这个问题。我发现 numpy 存在问题。我四处寻找,并从漫游文件夹中删除了 numpy:

C:\Users[名称]\AppData\Roaming\Python\Python35\site-packages

重新启动 PyCharm,它重新配置了自身,一切正常。不需要重新安装 numpy,因为之前在我的例子中,肯定存在版本不匹配的重复项。

答案4

下面为我​​修复了这个问题

sudo apt-get purge python-numpy
sudo pip uninstall numpy
sudo pip install numpy

我不得不多次执行“sudo pip uninstall numpy”

相关内容