我已经安装了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.
如何解决此问题?
答案 0 :(得分:2)
- (类型)CTRL + SHIFT + P
- (搜索:)打开设置
- (单击:)首选项:打开设置(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