319

I have a very similar question to this question, but I am 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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Seb
  • 3,655
  • 3
  • 17
  • 17
  • 3
    Check if there's a ``numpy`` directory under ``C:\Python3x\Libs\site-packages`` (I might remember the path name wrong). – codeape Oct 19 '11 at 09:00
  • 1
    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 :) – Janos Vinceller Feb 22 '20 at 09:05
  • 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](https://stackoverflow.com/a/38330088/1083292)) The previous Python installation I had was not only redundant but only caused me trouble. – erezmk Oct 05 '18 at 23:24
  • 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. – Delyar Tabatabai Feb 10 '22 at 23:21

27 Answers27

368

You can simply use

pip install numpy

Or for python3, use

pip3 install numpy
Daniel Patru
  • 1,968
  • 18
  • 15
Andrei Madalin Butnaru
  • 3,924
  • 2
  • 13
  • 7
  • This worked for me after also installing python-dev, so thank you. :) – Vaughany Mar 02 '16 at 21:22
  • 5
    @JeremyUpsal What happens if you just use pip? Does it not install the proper version of numpy?? – almost a beginner Sep 27 '16 at 10:28
  • 54
    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. – Hatchling Nov 11 '16 at 23:37
  • 9
    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...". – Arshin Sep 03 '18 at 07:11
  • 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: https://stackoverflow.com/a/41501815/4575793 – Cadoiz May 18 '20 at 12:55
  • 7
    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. – Peter Leopold May 21 '20 at 20:50
  • 4
    @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. – Andrei Madalin Butnaru May 25 '20 at 08:49
  • 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. – Luther Jun 21 '20 at 19:23
  • 2
    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. – Kokodoko Sep 18 '20 at 11:43
  • 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 Apr 14 '21 at 19:08
  • @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! – Genci Ymeri Apr 15 '21 at 02:19
  • Experience with fresh install of Python 3.10.7 for Windows: `pip install numpy` and `pip3 install numpy` both fail; `py -m pip install numpy` works. Digging into this, "py.exe" is the [Python Launcher for Windows](https://docs.python.org/3/using/windows.html#python-launcher-for-windows). I haven't found where my python installation actually _is_ yet. – Robert Calhoun Sep 23 '22 at 00:57
140

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
Dalton Cézane
  • 3,672
  • 2
  • 35
  • 60
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • 8
    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- https://pypi.org/project/numpy/1.8.2/ – Md.Habibur Rahman May 11 '20 at 20:59
  • 20
    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 Sep 18 '20 at 11:42
  • 3
    At this time on windows, "py -m pip install numpy" is working for me. Seems python3 is no more relevent. – Malik Khalil May 17 '21 at 16:36
39

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
MechtEngineer
  • 547
  • 6
  • 12
17

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
legoscia
  • 39,593
  • 22
  • 116
  • 167
Haimei
  • 12,577
  • 3
  • 50
  • 36
17

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.

Mamad Farrahi
  • 394
  • 1
  • 5
  • 20
Bill
  • 10,323
  • 10
  • 62
  • 85
  • 13
    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 ? – Cheeso Nov 01 '17 at 00:46
  • 1
    @Cheeso I only wish I could remember now. I presume I removed whatever edit I had made to .bash_profile and then reinstalled conda. – Bill May 24 '18 at 19:26
12

You can try:

py -3 -m  pip install anyPackageName

In your case use:

py -3 -m  pip install numpy
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Clinton Roy
  • 2,659
  • 2
  • 10
  • 7
11

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

Ateik
  • 2,458
  • 4
  • 39
  • 59
10

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

Nigrimmist
  • 10,289
  • 4
  • 52
  • 53
  • 2
    just a note: the question is not strictly related to Dockerfile (even if this answer helped me, thanks Nigrimmist). – Davide Mar 05 '19 at 22:59
9

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.

Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • 1
    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. – greendino Mar 20 '20 at 08:45
9

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/

naeg
  • 3,944
  • 3
  • 24
  • 29
  • Thank you, I spent yesterday trying to find that version. Is there a scipy3 perchance? – Seb Oct 19 '11 at 09:28
  • yes, here: http://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. – naeg Oct 19 '11 at 10:46
9

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!

Chet
  • 21,375
  • 10
  • 40
  • 58
7

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'
>>>
Vikram S
  • 551
  • 5
  • 5
7

For those using python 2.7, should try:

apt-get install -y python-numpy

Instead of pip install numpy

georgeos
  • 2,351
  • 2
  • 24
  • 28
5

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

Clay H
  • 651
  • 9
  • 21
4

Those who are using xonsh, do xpip install numpy.

Necktwi
  • 2,483
  • 7
  • 39
  • 62
3

For installing NumPy via Anaconda(use below commands):

  • conda install -c conda-forge numpy
  • conda install -c conda-forge/label/broken numpy
3
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))...
zzapper
  • 4,743
  • 5
  • 48
  • 45
3

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.

Shubhzgang
  • 322
  • 2
  • 9
2

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.

zhangyi
  • 41
  • 1
1

I did everything from the answers here but nothing worked. So I deleted all the previous installations of numpy using the commands below.

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

Then just install using pip3.

sudo pip3 install numpy
Dharman
  • 30,962
  • 25
  • 85
  • 135
Noman
  • 21
  • 5
1

Run

conda update --all

PS recall calling python using either "python2" or "python3" (not merely "python").

Itamar cohen
  • 59
  • 1
  • 5
0

solution for me - I installed numpy inside a virtual environment, but then running ipython was not inside virtual env:

(venv) ➜  which python
/Users/alon/code/google_photos_project/venv/bin/python
(venv) ➜  which ipython
/usr/bin/ipython

so I had to install ipython, and run ipython from the venv like this:

python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'
Alon Gouldman
  • 3,025
  • 26
  • 29
0

I was trying to use NumPy in Intellij but was facing the same issue so, I figured out that NumPy also comes with pandas. So, I installed pandas with IntelliJ tip and later on was able to import NumPy. Might help someone someday!

whatsinthename
  • 1,828
  • 20
  • 59
0

As stated in other answers, this error may refer to using the wrong python version. In my case, my environment is Windows 10 + Cygwin. In my Windows environment variables, the PATH points to C:\Python38 which is correct, but when I run my command like this:

./my_script.py

I got the ImportError: No module named numpy because the version used in this case is Cygwin's own Python version even if PATH environment variable is correct. All I needed was to run the script like this:

py my_script.py

And this way the problem was solved.

Metafaniel
  • 29,318
  • 8
  • 40
  • 67
0

Try uninstalling and then reinstalling the Python extension for VSCode.

I tried many different solutions, but this "hard refresh" was the only one that worked for me.

0

I just had the same problem as well! It turns out the problem happens when you're installing Numpy to a version of python and trying to run the program using another python version. Probably the global version of Python your text editor opens by default is different from the one that you need for the version of numpy you are running.

So to start off, run:

which python
python --version
which pip
pip list

If you can find numpy on the list, its most likely the python version you are using is not compatible with the version of numpy installed. Try switching to a different version of Python in this case.

If numpy is not installed just pip install numpy or pip3 install numpy depending upon your version of python.

Rishabh
  • 81
  • 2
  • 8
-1

On MacOs, if you are getting this error in Pycharm and you installed Python3 and NumPy through Homebrew, the python interpreter path is probably not pointing to the Python interpreter that is installed by Homebrew. In Pycharm, go to Preferences>Project: [Project Name]>Python Interpreter, and enter /opt/homebrew/bin/python3 for the path to python interpreter.