VS Code uses Anaconda Python to compile errors
table of Contents
Problem Description
- In VS Code, when using Anaconda Python to compile a .py program, an error is reported, and the error content is as follows:
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: 找不到指定的模块。
- Finding a lot of information, including reinstalling Numpy, can not solve the problem; note that VS Code has been executed first
conda activate base
;
problem solved
-
import numpy
No error is reported when executed with Anaconda Prompt (anaconda3) , indicating that there is no problem with numpy;
-
In Power Shell, the execution
conda activate base
fails; it prompts that the shell needs to be configured;
-
Execute
conda init powershell
commands to configure Power Shell;
-
Reopen Power Shell and prompt the following message:
. : 无法加载文件 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
-
Reference blog: https://blog.csdn.net/l_x_cser/article/details/104956657 to solve this problem;
-
Re-open Power Shell, Power Shell automatically enters base, runs python, and executes
import numpy
without error, indicating that the problem has been solved, just turn off the automatic activate base; -
Execute the command
conda config --set auto_activate_base false
to close the automatic activate_base; -
Reopen the Power Shell, the execution is
conda activate base
successful, run python, the executionimport numpy
does not report an error, the problem is solved;