Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
808 views
in Technique[技术] by (71.8m points)

python 3.x - How to fix 'ImportError: DLL load failed' in Visual Studio Code (packages installed with Anaconda)

I have installed Anaconda (with the packages that come with it) and VS Code (from within the Anaconda Navigator). If I open VS Code from the Anaconda Navigator or from The Anaconda Prompt, every import works well. But if I open VS Code directly, it throws an ImportError.

For example:

from PIL import Image

Gives the following error:

Traceback (most recent call last):
    File "c:MyProgramsCodingScriptsimageOperations.py", line 7, in 
    <module>
        from PIL import Image
    File "C:MyProgramsCodingSoftwarePythonlibsite- 
    packagesPILImage.py", line 93, in <module>
        from . import _imaging as core
ImportError: DLL load failed: The specified module could not be found.

How do I fix this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. (type) CTRL + SHIFT + P
  2. (search for:) open settings
  3. (click:) Preferences: Open Settings (JSON)

Then add three line configuration:

{
    ... # 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"
}

Finally, Restart your VScode


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...