如何修复Visual Studio代码(随Anaconda安装的程序包)中的“导入错误:DLL加载失败”

时间:2019-06-27 07:38:00

标签: python-3.x dll visual-studio-code anaconda importerror

我已经安装了Anaconda(及其附带的软件包)和VS Code(在Anaconda Navigator中)。如果我从Anaconda Navigator或Anaconda Prompt打开VS Code,则每个import都可以正常工作。 但是,如果我直接打开VS Code,则会抛出一个ImportError

例如:

from PIL import Image

给出以下错误:

Traceback (most recent call last):
    File "c:\MyPrograms\Coding\Scripts\imageOperations.py", line 7, in 
    <module>
        from PIL import Image
    File "C:\MyPrograms\Coding\Software\Python\lib\site- 
    packages\PIL\Image.py", line 93, in <module>
        from . import _imaging as core
ImportError: DLL load failed: The specified module could not be found.

如何解决此问题?

1 个答案:

答案 0 :(得分:2)

  1. (类型)CTRL + SHIFT + P
  2. (搜索:)打开设置
  3. (单击:)首选项:打开设置(JSON)

然后添加三行配置:

{
    ... # any other settings you have already added (remove this line)

    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    "terminal.integrated.shellArgs.windows": ["/K", "C:\\Anaconda3\\Scripts\\activate.bat C:\\Anaconda3"],
    "python.condaPath": "C:\\Anaconda3\\Scripts\\conda.exe"
}

最后,重新启动您的VScode