问题描述
我在 conda 中创建了一个虚拟环境。然后我在 anaconda 提示符 (conda activate
) 上打开了环境。然后,我安装了我打算在该环境中使用的任何软件包(例如 numpy)。
当我打开 jupyter notebook 并运行 import numpy
时,这会显示错误
ImportError Traceback (most recent call last)
~\anaconda3\envs\new1\lib\site-packages\numpy\core\__init__.py in <module>
21 try:
---> 22 from . import multiarray
23 except ImportError as exc:
~\anaconda3\envs\new1\lib\site-packages\numpy\core\multiarray.py in <module>
11
---> 12 from . import overrides
13 from . import _multiarray_umath
~\anaconda3\envs\new1\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)
ImportError: DLL load Failed: The specified module Could not be found.
During handling of the above exception,another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-5-d4cdadb62aa7> in <module>
----> 1 import numpy
~\anaconda3\envs\new1\lib\site-packages\numpy\__init__.py in <module>
143 from . import _distributor_init
144
--> 145 from . import core
146 from .core import *
147 from . import compat
~\anaconda3\envs\new1\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.7 from "C:\Users\<my user>\anaconda3\envs\new1\python.exe"
* The NumPy version is: "1.20.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load Failed: The specified module Could not be found.
我试过跑步
python
>>>import numpy
在 anaconda 提示符下,它确实成功导入了它。即使在 jupyter notebook 中,当我运行 help("modules")
时,numpy 也会显示为列出的模块之一。
预期行为是应导入已安装的模块。
如果有任何遗漏,请告诉我,这是我在 stackoverflow 上的第一篇文章。
解决方法
通常您会打开 anaconda 导航器,然后转到左侧的环境,然后在底部单击“添加”以添加新环境。之后,您单击新创建的环境并“打开终端”。在该终端中您使用:conda install -c anaconda numpy
。现在,您应该可以直接从 anaconda 导航器打开 jupyter 笔记本,也可以通过终端启动它,一切正常。
如果它仍然不起作用,请尝试重新启动 anaconda,它不应该被要求,但有时它对我有用。