Python 导入错误:没有名为 numpy 的模块

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

ImportError: No module named numpy

pythonnumpy

提问by user1784467

I'm trying to run a program that requires Numpy to be installed. I thought it was, because if I try sudo apt-get install python-numpyit tells me that

我正在尝试运行一个需要安装 Numpy 的程序。我以为是,因为如果我尝试sudo apt-get install python-numpy它会告诉我

sudo apt-get install python-numpy

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-numpy is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

But then when I go to install the program I'm trying to (within that programs directory, where setup.py is located) I get:

但是当我去安装我想要安装的程序时(在 setup.py 所在的程序目录中)我得到:

python setup.py install
Traceback (most recent call last):
   File "setup.py", line 20, in <module>
    from weblogolib import __version__
  File "/home/chris/Documents/IS/Bioinformatics-Software/weblogo-3.3/weblogolib/__init__.py", line 108, in <module>
     from numpy import array, asarray, float64, ones, zeros, int32,all,any, shape
ImportError: No module named numpy

When I look in the Python-2.7.3/Lib/site-packages directory the only thing that's in there is a README file. Shouldn't there be stuff from Numpy in there (and other install Python modules)?

当我查看 Python-2.7.3/Lib/site-packages 目录时,只有一个 README 文件。那里不应该有来自 Numpy 的东西(和其他安装 Python 模块)吗?

I am running Ubuntu 12.04 with Python 2.7

我正在使用 Python 2.7 运行 Ubuntu 12.04

Using dpkg -l python-numpyI get:

使用dpkg -l python-numpy我得到:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
ii  python-numpy   1:1.6.1-6ubunt Numerical Python adds a fast array facility

采纳答案by gpoo

You do not mention where you are running the commands. For the commands, I guess you are using Ubuntu 12.10.

你没有提到你在哪里运行命令。对于命令,我猜您正在使用Ubuntu 12.10.

In Ubuntu 12.10 the default is Python3 (check it with python --version). So that, when you ran python setup ..., you are running it with the default python available. For what it is worth, weblog 3.3 requires Python 2.5, 2.6 or 2.7.

在 Ubuntu 12.10 中,默认值为 Python3(使用 进行检查python --version)。因此,当您运行 时python setup ...,您正在使用默认的 python 运行它。就其价值而言,weblog 3.3 需要 Python 2.5、2.6 或 2.7。

Also, you can check where python-numpy was installed (check it with dpkg -L python-numpy).

此外,您可以检查 python-numpy 的安装位置(使用 进行检查dpkg -L python-numpy)。

My shot out of the blue would be:

我的出手将是:

$ python2.7 setup.py install

If you do not have installed python2.7, you should install it (likely, the shell is going to suggest it).

如果你还没有安装python2.7,你应该安装它(很可能,shell会建议它)。

回答by Equation Solver

I solved it by using following command to install the numpy module in my Ubuntu system.

我通过使用以下命令在我的 Ubuntu 系统中安装 numpy 模块来解决它。

On debian/ubuntu:

在 debian/ubuntu 上:

aptitude install python-numpy