fixingstuff
fixingstuff

Reputation: 579

"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:

import matplotlib.pyplot as plt

I get the response

"DLL load failed: The specified module could not be found"

I use Visual Studio Code on Windows 10 and am a beginner with Python. I run Python 3.7 and installed everything using 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.

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.

Upvotes: 11

Views: 16200

Answers (2)

bartkej
bartkej

Reputation: 51

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:

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

This will force env activation and worked for me pretty well. 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.

Upvotes: 5

Milad Sikaroudi
Milad Sikaroudi

Reputation: 717

This issue happens when you run VS code standalone and not in the anaconda prompt. The more complicated solution is to add anaconda path to your system path and make VSCode understand the conda virtual environment. But the simpler solution is to open anaconda prompt and then type:

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

to open VSCode through anaconda. Hope it works.

Upvotes: 28

Related Questions