0

ImportError: DLL load failed

import matplotlip.pyplot as plt

I realize that similar question are posted and answered but I don't know what to do in my case. The code below runs in Spyder but in VSCode it returns ' ImportError: DLL load failed' as it fails at 'import matplotlib.pyplot as plt' . The Python versions in both Spyder and VSCode are the same, the paths are almost see the same except for the bold onens (see below). I'm on W10 and I already reinstalled VSCode and Anaconda. The question is what can I do to resolve this?

from numpy.random import randn
import sys
import sys
print (sys.path)
print(sys.version)
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(3,1,1) # ( grid = (row nr. , columnr), plot nummmer)
ax1.hist(randn(100), bins=20, color='g', alpha=0.3)
ax1.set_xlabel('X - value')
ax1.set_ylabel('Y - value')
plt.show()

VSCODE

print(sys.path)

['c:\Users\erikv\Documents\MyPy\Script', 'c:\Users\erikv\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles', 'C:\Users\erikv\Documents\MyPy\Script', 'C:\Users\erikv\Anaconda3\python37.zip', 'C:\Users\erikv\Anaconda3\DLLs', 'C:\Users\erikv\Anaconda3\lib', 'C:\Users\erikv\Anaconda3', 'C:\Users\erikv\Anaconda3\lib\site-packages', 'C:\Users\erikv\Anaconda3\lib\site-packages\win32', 'C:\Users\erikv\Anaconda3\lib\site-packages\win32\lib', 'C:\Users\erikv\Anaconda3\lib\site-packages\Pythonwin']

print(sys.version)

3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]

SPYDER

print(sys.path)

['C:\Users\erikv', 'C:\Users\erikv', 'C:\Users\erikv\Documents\MyPy\Script', 'C:\Users\erikv\Anaconda3\python37.zip', 'C:\Users\erikv\Anaconda3\DLLs', 'C:\Users\erikv\Anaconda3\lib', 'C:\Users\erikv\Anaconda3', ' ', 'C:\Users\erikv\Anaconda3\lib\site-packages', 'C:\Users\erikv\Anaconda3\lib\site-packages\win32', 'C:\Users\erikv\Anaconda3\lib\site-packages\win32\lib', 'C:\Users\erikv\Anaconda3\lib\site-packages\Pythonwin', 'C:\Users\erikv\Anaconda3\lib\site-packages\IPython\extensions', 'C:\Users\erikv\.ipython']

print(sys.version):

3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]

Community
  • 1
  • 1
EvR020
  • 21
  • 1
  • 1
  • 9
  • Title a bit cryptic. The code runs in Spyder but it does **NOT** run in VSCode – EvR020 Oct 06 '19 at 14:19
  • I was inspired by solution https://stackoverflow.com/questions/54063285/numpy-is-already-installed-with-anaconda-but-i-get-an-importerror-dll-load-fail I compared results for os.environ['PATH'] for Spyder with VSCode. It turned out that in Spyder there were 3 paths that wer not available in VSCode: C:\\Users\\erikv\\Anaconda3\\Library\\mingw-w64\\bin; C:\\Users\\erikv\\Anaconda3\\Library\\usr\\bin; C:\\Users\\erikv\\Anaconda3\\Library\\bin; I added these to the Path in Environment variables of Windows. This works but I am still a bit puzzled why this is required now. – EvR020 Oct 06 '19 at 19:37
  • How are you trying to run this code? This kind of error typically occurs when you try running without activating the conda environment. – Brett Cannon Oct 08 '19 at 00:37

0 Answers0