简体   繁体   中英

Exception has occurred: ImportError "No module named 'numpy.core._multiarray_umath'"

WHAT I'M DOING:

I'm trying to import numpy:

import numpy

but I'm getting the following error:

Exception has occurred: 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.9 from "C:\Users\jack_l\AppData\Local\Programs\Python\Python39\python.exe"
  * The NumPy version is: "1.22.4"

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'

During handling of the above exception, another exception occurred:

I've gone through the help website and I couldn't find anything that helped (I tried everything, but IDK if I tried everything correctly :/).

WHAT I'VE DONE AND WHAT I'VE FOUND:

  • I currently have two versions of python installed on my device (3.9 and 3.10), and I think this may be causing the problem.
  • I'm using VSCode, and my interpreter is on Python 3.9.13 (image 1), but when I do py --version in the PowerShell terminal, it says I'm on Python 3.10.4 (image 2)
  • When I print os.environ.get('PYTHONPATH') , it gives me c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages , which I don't think is right but I don't know how to fix it.

Image 1:

在此处输入图像描述

Image 2:

在此处输入图像描述

FULL ERROR TRACEBACK:

Traceback (most recent call last):
  File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\core\__init__.py", line 23, in <module>
    from . import multiarray
  File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\core\multiarray.py", line 10, in <module>
    from . import overrides
  File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\core\overrides.py", line 6, in <module>
    from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\jack_l\Documents\CAR_MIX\mega.py", line 8, in <module>
    import numpy as np
  File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\__init__.py", line 144, in <module>
    from . import core
  File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\core\__init__.py", line 49, 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.9 from "C:\Users\jack_l\AppData\Local\Programs\Python\Python39\python.exe"
  * The NumPy version is: "1.22.4"

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'

If you recive this error probably the numpy library was installed in something like this: C:\Users\Administrator\AppData\Local\Programs\Python\Python38\Lib .I think that you have used pip install numpy out of the virtual environment and when you have imported numpy, Python couldn't find it.To fix it try to install numpy in virtual environment and it will be stored at name_virtualenv/Lib/site-packeges .

Create virtual environment:

python -m virtualenv name The folders Include, Scripts and Lib will be created automatically

Activate

Before activate the virtual environment go to name\Scripts cd name\Scripts

Then: .\activate

Install python-package

Install numpy with this command: pip install numpy . Now numpy is stored at this path: Lib/site-packeges

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM