Import Error: No module named numpy

1,206,786

Solution 1

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.

Or simply using pip:

python3 -m pip install numpy

Solution 2

You can simply use

pip install numpy

Or for python3, use

pip3 install numpy

Solution 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

Solution 4

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

Solution 5

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.

Share:
1,206,786

Related videos on Youtube

Seb
Author by

Seb

Updated on July 08, 2022

Comments

  • Seb
    Seb almost 2 years

    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

    • codeape
      codeape over 12 years
      Check if there's a numpy directory under C:\Python3x\Libs\site-packages (I might remember the path name wrong).
    • erezmk
      erezmk over 5 years
      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.
    • Janos Vinceller
      Janos Vinceller about 4 years
      Check the libraries loaded by typing python -c 'import sys; print sys.path' - for me I realized, I used the wrong python version, had to execute the script with python3 instead of python :)
    • Delyar Tabatabai
      Delyar Tabatabai about 2 years
      I had the same problem. I had numpy installed but was getting error 'no module named numpy'. I used pyCharm instead of VSCode and it was solved. Not sure where was the problem.
  • Seb
    Seb over 12 years
    Thank you, I spent yesterday trying to find that version. Is there a scipy3 perchance?
  • naeg
    naeg over 12 years
    yes, here: sourceforge.net/projects/scipy/files/scipy/0.10.0b2 you just have to visit www.scipy.org, click on download, go to the sourceforge site and click through the folders to get to that version.
  • Vaughany
    Vaughany about 8 years
    This worked for me after also installing python-dev, so thank you. :)
  • mkluwe
    mkluwe almost 8 years
    The user is on Windows, so apt-get won't help.
  • almost a beginner
    almost a beginner over 7 years
    @JeremyUpsal What happens if you just use pip? Does it not install the proper version of numpy??
  • Hatchling
    Hatchling over 7 years
    After doing this, and seeing it install, it still says ImportError: No module named 'numpy'. I tried installing a second time, it said it was already installed.
  • Cheeso
    Cheeso over 6 years
    You explained what the problem was, but you did not explain the solution. As a Python newbie, I don't grok the paths for my Anaconda installation . What specifically needs to be on the PATH ?
  • Bill
    Bill almost 6 years
    @Cheeso I only wish I could remember now. I presume I removed whatever edit I had made to .bash_profile and then reinstalled conda.
  • Arshin
    Arshin over 5 years
    In my case, pip install numpy or pip3 install numpy did not work as they defaulted the installation to python 3's package folders (for unknown reasons). I used pip2 install numpy to resolve the errors for "no module found...".
  • Davide
    Davide about 5 years
    just a note: the question is not strictly related to Dockerfile (even if this answer helped me, thanks Nigrimmist).
  • Benjamin Wall
    Benjamin Wall over 4 years
    unzip the package to what location?
  • greendino
    greendino about 4 years
    ERROR: Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
  • Md.Habibur Rahman
    Md.Habibur Rahman almost 4 years
    if you use pip3 install numpy by default it installs the numpy version 1.18.4, use specific version instead like this - pip install numpy==1.8.2 . check official doc for details- pypi.org/project/numpy/1.8.2
  • Cadoiz
    Cadoiz almost 4 years
    Of course, this has to be run inside the command line/terminal. On my system (Win10), pip was not added to PATH. Using where python and changing the directory to C:\this\excact\path\Scripts, I was then able to use it. See this answer: stackoverflow.com/a/41501815/4575793
  • Peter Leopold
    Peter Leopold almost 4 years
    pip3 install numpy" results in "Requirement already satisfied: numpy in c:\users\peter\appdata\local\programs\python\python36-32\lib‌​\site-packages". You'd expect python's "import numpy" would be able to find it, but no. ModuleNotFoundError: No module named 'numpy' So this answer may work in some narrow context, but not in general. There seems to be a lot more to do: configuring paths, etc.
  • Andrei Madalin Butnaru
    Andrei Madalin Butnaru almost 4 years
    @PeterLeopold Maybe you are having two versions of python in your system, and when you run pip3 install numpy the numpy package was installed into a specific version, and when you tried import numpy you used another python version. This happens to me all the time. Make sure that the environment / python version where you install/run the package is the same.
  • Luther
    Luther almost 4 years
    In my case my python script is called "test.py" -- if I opened my Anaconda prompt to my environment with numpy installed and typed "test.py" I would get the error about no module named numpy ... but if I type "python test.py" then it worked fine. Probably having to do with I installed Python via VS Community edition, and then later installed Anaconda to use Jupyter etc.
  • Kokodoko
    Kokodoko over 3 years
    In my case I get "requirement already satisfied" when I install numpy. But I still get "module not found" when I try to use it.
  • Kokodoko
    Kokodoko over 3 years
    It seems unavoidable to have many different versions of python and numpy scattered all over your system. I would like to know how you can avoid this and just use one version. I also get the error "module not found" even after installing numpy.
  • 幽幽子的筷子
    幽幽子的筷子 over 3 years
    pip3 may not refer to the python3 you use. run python3 -m pip install numpy instead.
  • Genci Ymeri
    Genci Ymeri about 3 years
    I have 3 diff computers, one mbPro, one iMac, one Dell WS win 10, all with diff setups, some with VS Code, some pyCharm. They all have the same issue and I have tried everything that's out there, still can't fix it. Ironically it works if I run Jupyter notebook, and due to time pressue I have no time to fix it...
  • Genci Ymeri
    Genci Ymeri about 3 years
    @AndreiMadalinButnaru Thank you. After reading your comment I went and double-checked the versions. I had two same versions installed (one from MS store installed probably with VS2019, and one from Python.org download executables) creating a real mess!
  • Malik Khalil
    Malik Khalil almost 3 years
    At this time on windows, "py -m pip install numpy" is working for me. Seems python3 is no more relevent.
  • Felipe
    Felipe over 2 years
    This worked out for me ...
  • Connor Clark
    Connor Clark almost 2 years
    Reader: You can replace py -3 with python3