简体   繁体   English

Windows VS 代码找不到 numpy 模块,即使它已安装(ModuleNotFoundError: No module named 'numpy.core._multiarray_umath')

[英]Windows VS Code can't find numpy Module even though it is installed (ModuleNotFoundError: No module named 'numpy.core._multiarray_umath')

I have been working with Anaconda and VS Code on my Windows and everything was fine until my computer once crashed.我一直在 Windows 上使用 Anaconda 和 VS 代码,一切都很好,直到我的电脑崩溃。 After that, I couldn't run my scripts that worked perfectly fine before.在那之后,我无法运行以前运行良好的脚本。

For example, I now get the the error when running:例如,我现在在运行时收到错误:

import os
import datetime

import IPython
import IPython.display
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import tensorflow as tf
from tensorflow import keras
from pmdarima import auto_arima
from kerastuner import HyperModel, Objective
from kerastuner import BayesianOptimization
import keras.backend as K
from tensorflow.keras.layers import (
    Dense,
    Dropout,
    LSTM,
    GRU
)


mpl.rcParams['figure.figsize'] = (8, 6)
mpl.rcParams['axes.grid'] = False

C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\__init__.py in <module>
     21 try:
---> 22     from . import multiarray
     23 except ImportError as exc:

~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\multiarray.py in <module>
     11 
---> 12 from . import overrides
     13 from . import _multiarray_umath

~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\overrides.py in <module>
      6 
----> 7 from numpy.core._multiarray_umath import (
      8     add_docstring, implement_array_function, _get_implementing_args)

ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-aaaeab3b7b86> in <module>
      4 import IPython
      5 import IPython.display
----> 6 import matplotlib as mpl
      7 import matplotlib.pyplot as plt
      8 import numpy as np

~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\__init__.py in <module>
    105 # cbook must import matplotlib only within function
    106 # definitions, so it is safe to import from it here.
--> 107 from . import cbook, rcsetup
    108 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
    109 from matplotlib.cbook import mplDeprecation  # deprecated

~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\cbook\__init__.py in <module>
     26 import weakref
     27 
---> 28 import numpy as np
     29 
     30 import matplotlib

~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\__init__.py in <module>
    138     from . import _distributor_init
    139 
--> 140     from . import core
    141     from .core import *
    142     from . import compat

~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\__init__.py in <module>
     46 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
     47         __version__, exc)
---> 48     raise ImportError(msg)
     49 finally:
     50     for envkey in env_added:

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\myname\AppData\Local\Programs\Python\Python39\python.exe"
  * The NumPy version is: "1.19.2"

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'

I have been reading multiple posts but couldn't find a solution.我一直在阅读多个帖子,但找不到解决方案。 I tried multiple things:我尝试了多种方法:

  • I have uninstalled and reinstalled anconda我已经卸载并重新安装了 anconda

  • I have added C:\Users\myname\AppData\Local\Programs\Python\Python39 to my system variable path我已将 C:\Users\myname\AppData\Local\Programs\Python\Python39 添加到我的系统变量路径

  • use pip uninstall numpy and after that conda install numpy使用 pip 卸载 numpy 然后 conda 安装 numpy

  • set my python path in VS code to either C:\Users\myname\AppData\Local\Programs\Python\Python39 (pythn verison 3.9.4) or C:\Users\myname\anaconda3 (Python version 3.8.5) set my python path in VS code to either C:\Users\myname\AppData\Local\Programs\Python\Python39 (pythn verison 3.9.4) or C:\Users\myname\anaconda3 (Python version 3.8.5)

  • I went to the link mentioned in the error message but couldn't find a solution我去了错误消息中提到的链接,但找不到解决方案

  • tried to upgarde my numpy version (I have 1.20.2)试图升级我的 numpy 版本(我有 1.20.2)

    (pip install numpy --upgrade Requirement already up-to-date: numpy in c:\users\myname\anaconda3\lib\site-packages (1.20.2)) (pip install numpy --upgrade 要求已经是最新的:numpy in c:\users\myname1.203\package.

  • Python Verison: 3.8.5 and 3.9.4 (tried both) Python 版本:3.8.5 和 3.9.4(都试过了)

  • Numpy Version: 1.20.1 Numpy 版本:1.20.1

  • Matplotlib Version: 3.4.1 Matplotlib 版本:3.4.1

This这个

import os
print(sys.version)
print("PYTHONPATH:", os.environ.get('PYTHONPATH'))
print("PATH:", os.environ.get('PATH'))

leads to this output:导致这个 output:

3.9.4 (tags/v3.9.4:1f2e308, Apr  6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)]
PYTHONPATH: c:\Users\myname\.vscode\extensions\ms-toolsai.jupyter-2021.5.745244803\pythonFiles;c:\Users\myname\.vscode\extensions\ms-toolsai.jupyter-2021.5.745244803\pythonFiles\lib\python
PATH: C:\Users\myname\anaconda3;C:\Users\myname\anaconda3\Library\mingw-w64\bin;C:\Users\myname\anaconda3\Library\usr\bin;C:\Users\myanme\anaconda3\Library\bin;C:\Users\myname\anaconda3\Scripts;C:\Users\myname\anaconda3\bin;C:\Users\myname\anaconda3\condabin;C:\Users\myname\anaconda3;C:\Users\myname\anaconda3\Library\mingw-w64\bin;C:\Users\myname\anaconda3\Library\usr\bin;C:\Users\myname\anaconda3\Library\bin;C:\Users\myname\anaconda3\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\MATLAB\R2020a\bin;C:\Users\myname\AppData\Local\Programs\Python\Python39;C:\Users\myname\AppData\Local\Microsoft\WindowsApps;C:\Users\myname\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\myname\AppData\Local\Programs\MiKTeX\miktex\bin\x64;C:\Users\myname\AppData\Local\Programs\Git\cmd;C:\Program Files (x86)\GitHub CLI;C:\Users\myname\AppData\Local\GitHubDesktop\bin

Thanks in advance for any help!提前感谢您的帮助!

You have a lot going on here, including multiple installations of Python.这里有很多事情要做,包括 Python 的多个安装。 It looks like you have both an Anaconda installation of Python, and a standard Python installation as well.看起来您既有 Anaconda 安装 Python,也有标准 Python 安装。

My first recommendation is to use virtual Python environments.我的第一个建议是使用虚拟 Python 环境。 These create isolated environments where you can install packages without worrying about messing up your base installation.这些创建了隔离的环境,您可以在其中安装软件包,而不必担心会弄乱您的基本安装。 There are a handful of ways to do this, Anaconda comes with Conda, and Python comes with venv.有几种方法可以做到这一点,Anaconda 带有 Conda,Python 带有 venv。 Both work well.两者都运作良好。 I prefer Conda.我更喜欢康达。

Step 1 - one or more of the packages in your standard Python installation are corrupted or incompatible;第 1 步 - 标准 Python 安装中的一个或多个包损坏或不兼容; I would recommend uninstalling completely.我建议完全卸载。

-- Windows Key > Settings (Gear icon) > Apps > Click on Python > Uninstall -- Windows 键 > 设置(齿轮图标)> 应用程序 > 点击 Python > 卸载

Step 2 - assuming your Anaconda installation is not also corrupted, we can use Conda to create a new environment.第 2 步 - 假设您的 Anaconda 安装也没有损坏,我们可以使用 Conda 创建一个新环境。

-- Windows Key > "Anaconda Prompt" > this opens a terminal with the base Anaconda environment. -- Windows Key > “Anaconda Prompt” > 这将打开一个带有基本 Anaconda 环境的终端。

conda create -n myenv python tensorflow ipython matplotlib pandas seaborn numpy -y

Step 3 - activate the environment to use it and install PyPi packages.第 3 步 - 激活环境以使用它并安装 PyPi 包。

conda activate myenv
pip install pmdarima

Fells like magic, but after applying the steps mentioned by @James, restarting my laptop, disabling and reenabling all extensions in VS Code as well as setting the environment to myenv in Anaconda itself before launching VS Code, it finally works now.就像魔术一样,但是在应用@James提到的步骤之后,重新启动我的笔记本电脑,禁用和重新启用 VS Code 中的所有扩展以及在启动 VS Code 之前将 Anaconda 本身的环境设置为 myenv ,它现在终于可以工作了。 Don't know what exactly made the difference though.不知道究竟是什么造成了差异。 Thanks again @James for the help!再次感谢@James 的帮助! 在启动 VS Code 之前将 Anaconda 本身的环境更改为 myenv

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError:matplotlib 导入时没有名为“numpy.core._multiarray_umath”的模块 - ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' on matplotlib import TensorFlow - ModuleNotFoundError:没有名为“numpy.core._multiarray_umath”的模块 - TensorFlow - ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' kivy 中没有名为“numpy.core._multiarray_umath”的模块 - No module named 'numpy.core._multiarray_umath' in kivy ModuleNotFoundError:没有名为“numpy.core._multiarray_umath”的模块(安装 TensorFlow 时) - ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' (While installing TensorFlow) 无法安装 numpy。 没有名为“numpy.core._multiarray_umath”的模块 - Unable to Install numpy. No module named 'numpy.core._multiarray_umath' 发生异常:ImportError &quot;No module named &#39;numpy.core._multiarray_umath&#39;&quot; - Exception has occurred: ImportError "No module named 'numpy.core._multiarray_umath'" pd.read_hdf抛出“无法将此数组的WRITABLE标志设置为True”和“没有名为“ numpy.core._multiarray_umath”的模块” - pd.read_hdf throws 'cannot set WRITABLE flag to True of this array' and 'No module named 'numpy.core._multiarray_umath' Pycharm 抛出:ModuleNotFoundError: No module named &#39;numpy&#39; 错误即使安装了 Numpy - Pycharm throws: ModuleNotFoundError: No module named 'numpy' error even though Numpy is installed ModuleNotFoundError:没有名为&#39;numpy&#39;的模块; 但numpy安装 - ModuleNotFoundError: No module named 'numpy'; but numpy installed “ModuleNotFoundError:即使安装了模块,也没有名为‘...’的模块 - "ModuleNotFoundError: No module named '…' even though module is installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM