首页 > 解决方案 > VScode 中的 Conda 环境

问题描述

我创建了两个 Anaconda 环境,比如 A 和 B,以及基本环境。我已经创建了环境 A 和 B 特定于我对它们所做的事情(不同的库)。

现在我安装了 VScode。当我打开 VScode 并首先在下部设置正确的解释器(A 或 B)并运行一些特定于 A 和 B 的 python 程序时,程序无法运行并出现错误。

D:\Anaconda\envs\practica-mldl\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
Traceback (most recent call last):
  File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\Do\Python\ML practice\iris\own-knn.py", line 15, in <module>
    import numpy as np
  File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core
  File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\core\__init__.py", line 48, 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
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.8 from "D:\Anaconda\envs\practica-mldl\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: DLL load failed while importing _multiarray_umath: The specified module could not be found.

PS D:\Do\Python\ML practice\iris> conda activate practica-mldl

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

但是当我通过anaconda提示打开VScode时,首先激活环境并通过键入代码并运行一些程序打开VScode,程序运行。

因此,据我了解,简单地更改 VScode 中的解释器与通过首先激活环境来打开 VScode 不同。我认为只需更改 VScode 中的解释器即可。

VScode 中是否有一个设置,我不必先激活环境来打开 VScode,这样我就可以运行特定于该环境的 python 程序?

非常感谢!

编辑 1. 添加错误

标签: pythonvisual-studio-codeanacondacondaenvironment

解决方案


推荐阅读