4

After I have reinstalled Anaconda, I can not import NumPy any more on Python 3:

import numpy as np

Output:

ModuleNotFoundError: No module named 'numpy'

I have tried

pip install numpy

I try to install it again, but I get:

pip install numpy

Output:

Requirement already satisfied: numpy in /anaconda3/lib/python3.7/site-packages (1.16.3)

Screenshot of some of the above

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
emax
  • 6,965
  • 19
  • 74
  • 141
  • 1
    And what did `numpy` installed correctly? Are you in a virtual environment? Have you tried `pip3 install numpy`? – Sebastien D May 22 '19 at 08:22
  • Sorry for my stupid question but when you call Python, you use `python3` in your shell? Maybe you have previous versions installed – Sebastien D May 22 '19 at 08:31
  • Yes I do. I added the screenshot of my terminal – emax May 22 '19 at 08:32
  • The canonical question for this problem on ***Windows*** may be *[Error "Import Error: No module named numpy" on Windows](https://stackoverflow.com/questions/7818811/)* (2011, 40 answers and 300 votes). – Peter Mortensen Aug 22 '22 at 15:11

3 Answers3

2

This command worked for me

python3 -m pip install numpy
aekber
  • 470
  • 1
  • 4
  • 12
1

You probably have multiple NumPy versions installed on your system and need to manually delete the old one.

  1. Open Terminal and run:

    pip list

  2. Remember or notate the NumPy version from the list

  3. Then run Python in Terminal or write and execute this code in your IDE:

    import numpy

    print(numpy) print(numpy.version)

  4. This should print two lines: numpy package location + numpy version like this:

    <module 'numpy' from '/usr/local/lib/python2.7/site-packages/numpy/init.pyc'> 1.16.1

  5. If the NumPy version reported here is different than the one reported by pip list, then go to the NumPy package location printed above and delete that package folder

  6. Try importing NumPy now. If you previously installed it, it should work. If you didn't install it then go and install it now. After installation all should work fine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tony
  • 7,767
  • 2
  • 22
  • 51
1

You are using a Conda environment to run your program. So you should run:

conda install numpy

If you use IDE like PyCharm, it will be easy to install packages by a mouse click (Install packages).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131