VS Code usa Anaconda Python para compilar errores

VS Code usa Anaconda Python para compilar errores

Descripción del problema

  • En VS Code, cuando se usa Anaconda Python para compilar un programa .py, se informa un error y el contenido del error es el siguiente:
PS C:\Users\VikingsWu\Desktop\code space> & C:/Users/VikingsWu/anaconda3/python.exe "c:/Users/VikingsWu/Desktop/code space/standardplot.py"
C:\Users\VikingsWu\anaconda3\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 "C:\Users\VikingsWu\anaconda3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "C:\Users\VikingsWu\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\Users\VikingsWu\anaconda3\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: 找不到指定的模块。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:/Users/VikingsWu/Desktop/code space/standardplot.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "C:\Users\VikingsWu\anaconda3\lib\site-packages\matplotlib\__init__.py", line 107, in <module>
    from . import cbook, rcsetup
  File "C:\Users\VikingsWu\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 28, in <module>
    import numpy as np
  File "C:\Users\VikingsWu\anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core
  File "C:\Users\VikingsWu\anaconda3\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
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.8 from "C:\Users\VikingsWu\anaconda3\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: 找不到指定的模块。
  • Encontrar mucha información, incluida la reinstalación de Numpy, no puede resolver el problema; tenga en cuenta que VS Code se ha ejecutado primero conda activate base;

problema resuelto

  • import numpyNo se informa ningún error cuando se ejecuta con Anaconda Prompt (anaconda3) , lo que indica que no hay ningún problema con numpy;
    Inserte la descripción de la imagen aquí

  • En Power Shell, la ejecución conda activate basefalla, indica que es necesario configurar el shell;
    Inserte la descripción de la imagen aquí

  • Ejecute conda init powershellcomandos para configurar Power Shell;
    Inserte la descripción de la imagen aquí

  • Vuelva a abrir Power Shell y muestre el siguiente mensaje:

. : 无法加载文件 C:\Users\VikingsWu\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本。有关详细信息,
请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'C:\Users\VikingsWu\Documents\WindowsPowerShell\profile.ps1'
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Inserte la descripción de la imagen aquí

  • Blog de referencia: https://blog.csdn.net/l_x_cser/article/details/104956657 para resolver este problema;

  • Vuelva a abrir Power Shell, Power Shell ingresará automáticamente a la base, ejecutará Python y se ejecutará import numpysin errores, lo que indica que el problema se ha resuelto, simplemente apague la base de activación automática;

  • Ejecute el comando conda config --set auto_activate_base falsepara cerrar la base de activación automática;

  • Vuelva a abrir el Power Shell, la ejecución es conda activate baseexitosa, ejecute Python, la ejecución import numpyno reporta un error, el problema está resuelto;
    Inserte la descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/weixin_41754258/article/details/114038073
Recomendado
Clasificación