EdouardIFP
EdouardIFP

Reputation: 293

DLL load failed : Python modules accessible through Spyder but import fail in cmd

I have seen many more or less related questions on this topic, but none helped me finding a way to solve my problem. I'm not very familiar with Windows environment, deep apologies if my question sounds obvious to some extent.

Setup:

Im running a Python, that involves several modules import. I came across some module issues. For example:

from PIL import Image as PIL_Image

Works smooth in Spyder, but gives (error message in french but I guess you got the point):

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Users\my_user_name\Anaconda3\lib\site-packages\PIL\Image.py", line 64, in <module>
    from . import _imaging as core
ImportError: DLL load failed: Le module spécifié est introuvable.

If executed in Powershell or cmd.

What I tried:

What else could explain that my import fails outside of Spyder ?

Upvotes: 2

Views: 3654

Answers (2)

Ahmet Demirkesen
Ahmet Demirkesen

Reputation: 1

I had the same problem when importing scipy related modules and after struggling for days, this solution had worked for me:

How I solved my issue:

  • Launch the Spyder editor.
  • Tools -> Current user environment variables
  • Double click "Path"
  • Edit these paths based on your installation:

X:ProgramDataAnaconda3 --> C:\Program Files\Anaconda3

X:ProgramDataAnaconda3Scripts --> C:\Program Files\Anaconda3\Scripts

X:ProgramDataAnaconda3Librarybin --> C:\Program Files\Anaconda3\Library\bin

Paths might differ based on your installation folder.

Upvotes: 0

EdouardIFP
EdouardIFP

Reputation: 293

Ok I could not find a clean way out, so let me just share my experience in case someone finds it helpful ...

The DLL failure with PIL related libs seems to be a known issue. See further explanations:

How I solved my issue:

  • Cleanly uninstalled anything related to Python on my laptop. Both Anaconda, isolated Python installs, Spyder ...
  • Re-installed the latest Anaconda. It happens to come with Python 3.7.1 instead of 3.7.0
  • Re-did my PIP installs of everything. Note I had to append Anaconda\Library\bin to my Windows path for PIP to work completely, which I don't recall having done with my previous installation.

Upvotes: 2

Related Questions