使用python3.2无法导入numpy

时间:2014-02-13 15:27:17

标签: python python-3.x numpy

我有Ubuntu 12.04,机器上有三个不同的python版本(python2.7,python3,python3.2)。我只能在python 2.7中获取要导入的包。每当我尝试在Python 3.2.3中导入它们时,我都会得到:

Python 3.2.3 (default, Jan 14 2014, 13:11:14) 
[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
>>> 

我已经看到围绕Stack的各种问题有类似的问题,但没有一个问题解决了我的问题。

例如,我运行了这段代码:

sudo apt-get install python3-numpy python3-scipy

结果如下:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-numpy is already the newest version.
python3-scipy is already the newest version.

所以,似乎我确实为python3安装了软件包,但无法将它们加载到python3.2.3环境中。

    >>> sys.path
    ['', '/usr/local/lib/python32.zip', '/usr/local/lib/python3.2',
 '/usr/local/lib/python3.2/plat-linux2', '/usr/local/lib/python3.2/lib-dynload', 
'/home/bre-dev-2/.local/lib/python3.2/site-packages', '/usr/local/lib/python3.2/site-packages']

所有的网站包都是空的,而文件夹usr / lib / python3 / dist-packages中存在numpy和scipy(注意路径名中没有“local”)。

最后,当我更改sys.path以包含numpy和scipy的目录时:

>>> sys.path[6]='/usr/lib/python3/dist-packages'
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in <module>
    from . import add_newdocs
  File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 4, in <module>
    from .type_check import *
  File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 8, in <module>
    import numpy.core.numeric as _nx
  File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 5, in <module>
    from . import multiarray
ImportError: cannot import name multiarray

有什么建议吗?开始失去理智......

1 个答案:

答案 0 :(得分:2)

在检测工作之后,怀疑:P,还有其他一些Python环境在起作用。现在,那是为什么呢? :-D

如果您想使用系统Python,请使用/usr/bin/python3强制它。这样你就可以使用你安装的Numpy了。

如果您希望将/usr/local/bin下的那个放在一边,只需将其重命名,以便它不会“隐藏”系统中的其他Pythons。请注意,/usr/local/bin优先于路径中的/usr/bin