VSCodeはAnacondaPythonを使用してエラーをコンパイルします
問題の説明
- VS Codeで、Anaconda Pythonを使用して.pyプログラムをコンパイルすると、エラーが報告され、エラーの内容は次のようになります。
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: 找不到指定的模块。
- Numpyの再インストールなど、多くの情報を見つけても問題を解決することはできません。VSCodeが最初に実行されていることに注意してください
conda activate base
。
問題が解決しました
-
Anaconda Prompt(anaconda3)
import numpy
で実行してもエラーは報告されません。これは、numpyに問題がないことを示しています。
-
Power Shellでは、実行は
conda activate base
失敗します。シェルを構成する必要があることを示すプロンプトが表示されます。
-
conda init powershell
コマンドを実行してPowerShellを構成します。
-
Power Shellを再度開き、次のメッセージを表示します。
. : 无法加载文件 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
-
この問題を解決するには、ブログを参照してください:https://blog.csdn.net/l_x_cser/article/details/104956657 ;
-
Power Shellを再度開くと、Power Shellは自動的にベースに入り、Pythonを実行し
import numpy
、エラーなしで実行されます。これは、問題が解決されたことを示します。ベースの自動アクティブ化をオフにするだけです。 -
コマンド
conda config --set auto_activate_base false
を実行して、自動activate_baseを閉じます。 -
Power Shellを再度開き、実行は
conda activate base
成功し、Pythonを実行import numpy
します。実行はエラーを報告せず、問題は解決します。