如何将包导入conda环境?

How to import packages to a conda environment?

我已经在 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 显示为列出的模块之一时。

预期的行为是应该导入已安装的模块。

此外,如果有任何遗漏,请告诉我,这是我在 Whosebug 上的第一个 post。

通常你会打开anaconda导航器,然后转到左侧的环境,然后在底部单击“添加”以添加新环境。之后,您单击新创建的环境和“打开终端”。在那个终端你使用:conda install -c anaconda numpy。现在您应该可以直接从 anaconda 导航器或通过终端启动它来打开您的 jupyter notebook,并且一切正常。

如果还是不行尝试重启anaconda,应该不需要,但有时对我有用。