1
votes

BACKGROUND

Just two days ago I was able to run any program that had a numpy dependency. Now when I try to run my code using pandas, matplotlib or any module that depends on numpy, I get the below error:

Traceback (most recent call last):

  File "<ipython-input-8-8fcf286af663>", line 7, in <module>
    import numpy

  File "path\to\Python\Python38\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core

  File "path\to\Python\Python38\site-packages\numpy\core\__init__.py", line 48, in <module>
    raise ImportError(msg)

ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.7 from "C:\ProgramData\Anaconda3\pythonw.exe"
  * The NumPy version is: "1.19.5"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

SETTINGS CHECK

The return message references this site: https://numpy.org/devdocs/user/troubleshooting-importerror.html but nothing there has helped me.

I checked my Path variable to make sure that all the required directory locations are there and there is no issue.

I successfully import numpy when I compile code from cmd using python -c "import numpy; print('done')"

I am using an anaconda environment, the Spyder IDE, and again it was just fine two days ago. enter image description here

I checked the python version from pythonw.exe and it seems fine as well enter image description here

What could be wrong with my environment?

ATTEMPTED SOLUTIONS HERE

Also, I've checked the following links with no success:

Importing the numpy c-extensions failed

importing numpy package in Spyder, Python

python Spyder not importing numpy

https://github.com/numpy/numpy/issues/15090

Can't import numpy anaconda

Import error: Anaconda numpy (numpy and Anaconda already installed, virtualenv)

1

1 Answers

1
votes

Turns out my problem was very simple. The main solution I was trying was to uninstall and reinstall.

Every time I installed and uninstalled the modules, I did so from the standard command line.

That was wrong since anaconda uses its own virtual environment to store data.

So all I had to do was run this command from the anaconda command prompt:

pip install --upgrade pandas && pip install --upgrade numpy

this command would work just as well:

pip uninstall pandas && pip uninstall numpy && pip install pandas

(since the last install would automatically download any dependencies that pandas has, which is numpy