【发布时间】:2021-04-20 12:35:44
【问题描述】:
我一直在我的 Windows 上使用 Anaconda 和 VS Code,一切都很好,直到我的电脑崩溃了。在那之后,我无法运行以前运行良好的脚本。
例如,我现在在运行时遇到错误:
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'
我已经阅读了多个帖子,但找不到解决方案。我尝试了多种方法:
-
我已经卸载并重新安装了 anconda
-
我已将 C:\Users\myname\AppData\Local\Programs\Python\Python39 添加到我的系统变量路径中
-
使用 pip 卸载 numpy,然后使用 conda 安装 numpy
-
在 VS 代码中将我的 python 路径设置为 C:\Users\myname\AppData\Local\Programs\Python\Python39 (pythn 版本 3.9.4) 或 C:\Users\myname\anaconda3 (Python 版本 3.8.5 )
-
我转到错误消息中提到的链接但找不到解决方案
-
试图升级我的 numpy 版本(我有 1.20.2)
(pip install numpy --upgrade 要求已经是最新的:c:\users\myname\anaconda3\lib\site-packages (1.20.2) 中的 numpy)
-
Python 版本:3.8.5 和 3.9.4(都试过了)
-
Numpy 版本:1.20.1
-
Matplotlib 版本:3.4.1
这个
import os
print(sys.version)
print("PYTHONPATH:", os.environ.get('PYTHONPATH'))
print("PATH:", os.environ.get('PATH'))
导致这个输出:
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
提前感谢您的帮助!
【问题讨论】:
标签: python windows numpy anaconda