简体   繁体   English

尝试在 Windows 10 上打开任何 Python 库时,Visual Studio Code 中的“DLL 加载失败”

[英]"DLL load failed" in Visual Studio Code when trying to open any Python library on Windows 10

When running a basic python program such as a single line of code:运行基本的python程序时,例如一行代码:

import matplotlib.pyplot as plt

I get the response我得到回应

"DLL load failed: The specified module could not be found" “DLL 加载失败:找不到指定的模块”

I use Visual Studio Code on Windows 10 and am a beginner with Python.我在 Windows 10 上使用 Visual Studio Code,并且是 Python 的初学者。 I run Python 3.7 and installed everything using Anaconda.我运行 Python 3.7 并使用 Anaconda 安装了所有东西。

I have added various system environment variables as proposed in this answer .我已经添加了这个答案中建议的各种系统环境变量。 I have verified that I can run the code in the Anaconda Powershell Prompt so there seems to be some problem between Visual Studio Code and Anaconda upon install.我已经验证我可以在 Anaconda Powershell Prompt 中运行代码,因此安装时 Visual Studio Code 和 Anaconda 之间似乎存在一些问题。

I have been reading this discussion which seems to relate to the problem but do not see that they offer a solution, merely that it is fixed.我一直在阅读这个似乎与问题有关的讨论,但没有看到他们提供了解决方案,只是解决了问题。

----------EDIT--------- - - - - - 编辑 - - - - -

I was able to load the libraries in Spyder (see comments) so the issue is perhaps somehow related to Visual Studio Code.我能够在 Spyder 中加载库(见评论),所以这个问题可能与 Visual Studio Code 有某种关系。

This issue happens when you run VS code standalone and not in the anaconda prompt.当您独立运行 VS 代码而不是在 anaconda 提示符下运行时,会发生此问题。 The more complicated solution is to add anaconda path to your system path and make VSCode understand the conda virtual environment.更复杂的解决方案是在你的系统路径中添加anaconda路径,让VSCode理解conda虚拟环境。 But the simpler solution is to open anaconda prompt and then type:但更简单的解决方案是打开 anaconda 提示符,然后键入:

    (base) C:\Users\{your_user}>conda activate {your_env}
    ({your_env}) C:\Users\{your_user}>code

to open VSCode through anaconda.通过anaconda打开VSCode。 Hope it works.希望它有效。

In your case it seems there is a problem with activation itself.在您的情况下,激活本身似乎存在问题。 You can still run VSC as standalone, but you just need to add those two crucial lines in teminal's 'settings.json' file:您仍然可以独立运行 VSC,但您只需要在终端的“settings.json”文件中添加这两个关键行:

"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe", 
"python.terminal.activateEnvironment": true

This will force env activation and worked for me pretty well.这将强制激活 env 并且对我来说效果很好。 I will try to analyze this issue in the future.以后我会尝试分析这个问题。 I hope this post could still be helpful as I did not find any fix nor satisfying explanation.我希望这篇文章仍然有帮助,因为我没有找到任何修复或令人满意的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM