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

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

我有一个与此问题非常相似的问题,但仍落后了一步。我在Windows 7(对不起)64位系统上仅安装了一个Python 3版本。

我在此链接后安装了numpy- 如问题中所述。安装进行得很好,但是当我执行时

import numpy

我收到以下错误:

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

我知道这可能是一个超级基本的问题,但我仍在学习。

谢谢

I have a very similar question to this question, but still one step behind. I have only one version of Python 3 installed on my Windows 7 (sorry) 64-bit system.

I installed numpy following this link – as suggested in the question. The installation went fine but when I execute

import numpy

I got the following error:

Import error: No module named numpy

I know this is probably a super basic question, but I’m still learning.

Thanks


回答 0

NumPy版本1.5.0中添加了对Python 3的支持,因此,首先必须下载/安装较新版本的NumPy。

Support for Python 3 was added in NumPy version 1.5.0, so to begin with, you must download/install a newer version of NumPy.


回答 1

您可以简单地使用

pip install numpy

或者对于python3,使用

pip3 install numpy

You can simply use

pip install numpy

Or for python3, use

pip3 install numpy

回答 2

我认为numpy的安装有问题。这是我解决此问题的步骤。

  1. 请访问此网站以下载正确的软件包:http : //sourceforge.net/projects/numpy/files/
  2. 解压包装
  3. 转到文件
  4. 使用此命令安装numpy: python setup.py install

I think there are something wrong with the installation of numpy. Here are my steps to solve this problem.

  1. go to this website to download correct package: http://sourceforge.net/projects/numpy/files/
  2. unzip the package
  3. go to the document
  4. use this command to install numpy: python setup.py install

回答 3

在Windows上安装Numpy

  1. 以管理员权限打开Windows命令提示符(快速方法:按Windows键。键入“ cmd”。右键单击建议的“命令提示符”,然后选择“以管理员身份运行”)
  2. 使用“ cd”(更改目录)命令导航到Python安装目录的Scripts文件夹。例如“ cd C:\ Program Files(x86)\ PythonXX \ Scripts”

这可能是:C:\ Users \\ AppData \ Local \ Programs \ Python \ PythonXX \ ScriptsC:\ Program Files(x86)\ PythonXX \ Scripts(其中XX代表Python版本号),具体取决于安装位置。使用Windows资源管理器查找文件夹,然后将其从资源管理器地址栏中粘贴或键入地址到命令提示符中,可能会更容易。

  1. 输入以下命令:“ pip install numpy”。

下载并安装软件包后,您应该会看到类似于以下文本的内容。

Collecting numpy
  Downloading numpy-1.13.3-2-cp27-none-win32.whl (6.7MB)  
  100% |################################| 6.7MB 112kB/s
Installing collected packages: numpy
Successfully installed numpy-1.13.3

Installing Numpy on Windows

  1. Open Windows command prompt with administrator privileges (quick method: Press the Windows key. Type “cmd”. Right-click on the suggested “Command Prompt” and select “Run as Administrator)
  2. Navigate to the Python installation directory’s Scripts folder using the “cd” (change directory) command. e.g. “cd C:\Program Files (x86)\PythonXX\Scripts”

This might be: C:\Users\\AppData\Local\Programs\Python\PythonXX\Scripts or C:\Program Files (x86)\PythonXX\Scripts (where XX represents the Python version number), depending on where it was installed. It may be easier to find the folder using Windows explorer, and then paste or type the address from the Explorer address bar into the command prompt.

  1. Enter the following command: “pip install numpy”.

You should see something similar to the following text appear as the package is downloaded and installed.

Collecting numpy
  Downloading numpy-1.13.3-2-cp27-none-win32.whl (6.7MB)  
  100% |################################| 6.7MB 112kB/s
Installing collected packages: numpy
Successfully installed numpy-1.13.3

回答 4

我也遇到了这个问题(导入错误:没有名为numpy的模块),但就我而言,这是我在Mac OS X中使用PATH变量时遇到的问题。我对.bash_profile文件进行了较早的编辑,该文件导致了Anaconda安装的路径(及其他)不能正确添加。

只要在这里将此注释添加到列表中,以防其他类似我的人以相同的错误消息来到此页面并且遇到与我相同的问题。

I also had this problem (Import Error: No module named numpy) but in my case it was a problem with my PATH variables in Mac OS X. I had made an earlier edit to my .bash_profile file that caused the paths for my Anaconda installation (and others) to not be added properly.

Just adding this comment to the list here in case other people like me come to this page with the same error message and have the same problem as I had.


回答 5

您安装了适用于Python 2.6的Numpy版本-因此您只能将其与Python 2.6一起使用。您必须安装适用于Python 3.x的Numpy,例如:http : //sourceforge.net/projects/numpy/files/NumPy/1.6.1/numpy-1.6.1-win32-superpack-python3.2.exe /下载

有关不同版本的概述,请参见此处:http : //sourceforge.net/projects/numpy/files/NumPy/1.6.1/

You installed the Numpy Version for Python 2.6 – so you can only use it with Python 2.6. You have to install Numpy for Python 3.x, e.g. that one: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/numpy-1.6.1-win32-superpack-python3.2.exe/download

For an overview of the different versions, see here: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/


回答 6

安装Numpy后,我也遇到了这个问题。我通过关闭Python解释器并重新打开解决了该问题。如果其他人有此问题,可能要尝试其他方法,也许可以节省几分钟!

I had this problem too after I installed Numpy. I solved it by just closing the Python interpreter and reopening. It may be something else to try if anyone else has this problem, perhaps it will save a few minutes!


回答 7

面对同样的问题

ImportError: No module named numpy

因此,在我们的情况下(我们使用的是PIP和python 2.7),解决方案是SPLIT pip install命令:

RUN pip install numpy scipy pandas sklearn

RUN pip install numpy scipy
RUN pip install pandas sklearn

在此处找到解决方案:https : //github.com/pandas-dev/pandas/issues/25193,它是pandas的最新更新到v0.24.0

Faced with same issue

ImportError: No module named numpy

So, in our case (we are use PIP and python 2.7) the solution was SPLIT pip install commands :

From

RUN pip install numpy scipy pandas sklearn

TO

RUN pip install numpy scipy
RUN pip install pandas sklearn

Solution found here : https://github.com/pandas-dev/pandas/issues/25193, it’s related latest update of pandas to v0.24.0


回答 8

我通过pip和conda在相同的环境中安装了numpy,仅删除并重新安装其中一个是不够的。

我不得不重新安装两个。

我不知道为什么突然发生,但是解决方案是

pip uninstall numpy

conda uninstall numpy

从康达卸载也删除torchtorchvision

然后

conda install pytorch-cpu torchvision-cpu -c pytorch

pip install numpy

这为我解决了这个问题。

I had numpy installed on the same environment both by pip and by conda, and simply removing and reinstalling either was not enough.

I had to reinstall both.

I don’t know why it suddenly happened, but the solution was

pip uninstall numpy

conda uninstall numpy

uninstalling from conda also removed torch and torchvision.

then

conda install pytorch-cpu torchvision-cpu -c pytorch

and

pip install numpy

this resolved the issue for me.


回答 9

在设置用于机器学习的python时,我也面临着phyton 3的上述问题。

我遵循以下步骤:

安装python-2.7.13.msi

•设置PATH = C:\ Python27

•设置PATH = C:\ Python27 \ Scripts

前往http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy

下载的:–numpy-1.13.1 + mkl-cp27-cp27m-win32.whl

          --scipy-0.18.0-cp27-cp27m-win32.whl 

安装numpy:pip install numpy-1.13.1 + mkl-cp27-cp27m-win32.whl

安装scipy:pip install scipy-0.18.0-cp27-cp27m-win32.whl

您可以使用以下cmds测试正确性:-

>>> import numpy
>>> import scipy
>>> import sklearn
>>> numpy.version.version
'1.13.1'
>>> scipy.version.version
'0.19.1'
>>>

I too faced the above problem with phyton 3 while setting up python for machine learning.

I followed the below steps :-

Install python-2.7.13.msi

• set PATH=C:\Python27

• set PATH=C:\Python27\Scripts

Go to http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy

Downloaded:- — numpy-1.13.1+mkl-cp27-cp27m-win32.whl

          --scipy-0.18.0-cp27-cp27m-win32.whl 

Installing numpy: pip install numpy-1.13.1+mkl-cp27-cp27m-win32.whl

Installing scipy: pip install scipy-0.18.0-cp27-cp27m-win32.whl

You can test the correctness using below cmds:-

>>> import numpy
>>> import scipy
>>> import sklearn
>>> numpy.version.version
'1.13.1'
>>> scipy.version.version
'0.19.1'
>>>

回答 10

我不确定为什么会收到错误消息,但pip3 uninstall numpy随后pip3 install numpy为我解决了该问题。

I’m not sure exactly why I was getting the error, but pip3 uninstall numpy then pip3 install numpy resolved the issue for me.


回答 11

通过Anaconda安装NumPy(使用以下命令):

  • conda安装-c conda-forge numpy
  • conda install -c conda-forge / label /破碎的numpy

For installing NumPy via Anaconda(use below commands):

  • conda install -c conda-forge numpy
  • conda install -c conda-forge/label/broken numpy

回答 12

那些正在使用的人会xonshxpip install numpy

Those who are using xonsh, do xpip install numpy.


回答 13

对于使用python 2.7的用户,应尝试:

apt-get install -y python-numpy

而不是pip install numpy

For those using python 2.7, should try:

apt-get install -y python-numpy

Instead of pip install numpy


回答 14

你可以试试:

py -3 -m pip安装anyPackageName

在您的情况下使用:

py -3 -m pip安装numpy

谢谢

You can try:

py -3 -m pip install anyPackageName

In your case use:

py -3 -m pip install numpy

Thanks


回答 15

这是numpy版本的问题,请查看$ CAFFE_ROOT / python / requirement.txt。然后执行:sudo apt-get install python-numpy> = xxx,这个问题将会解决。

this is the problem of the numpy’s version, please check out $CAFFE_ROOT/python/requirement.txt. Then exec: sudo apt-get install python-numpy>=x.x.x, this problem will be sloved.


回答 16

import numpy as np
ImportError: No module named numpy 

即使知道安装了numpy并尝试了上述所有建议都没有成功,我还是得到了这个。对我来说,解决方法是删除as np 并直接引用模块。(Centos上的python 3.4.8)。

import numpy
DataTwo=numpy.stack((OutputListUnixTwo))...
import numpy as np
ImportError: No module named numpy 

I got this even though I knew numpy was installed and unsuccessfully tried all the advice above. The fix for me was to remove the as np and directly refer to modules . (python 3.4.8 on Centos) .

import numpy
DataTwo=numpy.stack((OutputListUnixTwo))...

回答 17

您应该尝试使用以下一种安装numpy:

pip install numpy
pip2 install numpy
pip3 install numpy

由于某种原因,在我的情况下,pip2解决了该问题

You should try to install numpy using one of those:

pip install numpy
pip2 install numpy
pip3 install numpy

For some reason in my case pip2 solved the problem


回答 18

在尝试了来自各个站点的许多建议和类似问题之后,对我有用的是卸载所有Python东西并仅重新安装Anaconda(请参阅https://stackoverflow.com/a/38330088/1083292

我以前的Python安装不仅多余,而且还给我带来了麻烦。

After trying many suggestions from various sites and similar questions, what worked for me was to uninstall all Python stuff and reinstall Anaconda only (see https://stackoverflow.com/a/38330088/1083292)

The previous Python installation I had was not only redundant but only caused me trouble.


回答 19

如果在重新安装python之前工作正常,则可以解决此问题。

我只是使用以下方法解决了此问题: 如何使用自制软件在macOS中安装Python 3的早期版本?

If it was working before reinstalling python would solve the issue.

I just hit and resolved this issue using: How can I install a previous version of Python 3 in macOS using homebrew?


回答 20

对我来说,在Windows 10上,我在不知不觉中安装了多个python版本(一个来自PyCharm IDE,另一个来自Windows应用商店)。我从Windows Store卸载了一个,为了更彻底,卸载了numpy pip uninstall numpy,然后再次安装了它pip install numpy。它在PyCharm的终端和命令提示符中都可以使用。

For me, on windows 10, I had unknowingly installed multiple python versions (One from PyCharm IDE and another from Windows store). I uninstalled the one from windows Store and just to be thorough, uninstalled numpy pip uninstall numpy and then installed it again pip install numpy. It worked in the terminal in PyCharm and also in command prompt.