2

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:

  • Windows 10
  • Python 3.7.0 (installed through latest Anaconda release)
  • Spyder 3.3.1

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:

  • Appending Anaconda's install path to my path variable before I open Powershell:

    $Env:path += ";C:\Users\my_user_name\Anaconda3;C:\Users\my_user_name\Anaconda3\Scripts"
    
  • Checking that sys.path is the same in Powershell and Spyder. For both, it looks like:

     ['',
      'C:\\Users\\my_user_name',
      'C:\\Users\\my_user_name\\Anaconda3\\python37.zip',
      'C:\\Users\\my_user_name\\Anaconda3\\DLLs',
      'C:\\Users\\my_user_name\\Anaconda3\\lib',
      'C:\\Users\\my_user_name\\Anaconda3',
      'C:\\Users\\my_user_name\\AppData\\Roaming\\Python\\Python37\\site-packages',
      'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages',
      'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\win32',
      'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\win32\\lib',
      'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\Pythonwin',
      'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
      'C:\\Users\\my_user_name\\.ipython']
    

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

Mofi
  • 46,139
  • 17
  • 80
  • 143
EdouardIFP
  • 273
  • 2
  • 10
  • By any chance, where is this dll located? – Torxed Feb 16 '19 at 07:47
  • I did a search on _imaging and found two relevant hits: one in Anaconda3/Lib/site-packages/PIL and one in Anaconda3\pkgs\pillow-5.2.0-py37h08bbbbd_0\Lib\site-packages\PIL – EdouardIFP Feb 16 '19 at 11:17
  • `Anaconda3/Lib/site-packages/PIL` is not in your path, and not the other either. No idea what sort of magic Spyder or Anaconda does. I prefer to run things in a terminal as-is.. So I'm of no use here sadly. – Torxed Feb 16 '19 at 11:33
  • It seems you're using Powershell, try to run cmd instead and see if that works. – Carlos Cordoba Feb 17 '19 at 13:30
  • Unfortunately, cmd gives exactly the same thing. – EdouardIFP Feb 17 '19 at 17:52
  • I've seen problems like this before, and had them myself. The `PATH` variable is unrelated to python import errors. Would you be able to give us a list of every file inside the `\site-packages\PIL` including files in subfolders? – Legorooj Feb 17 '19 at 20:06

2 Answers2

2

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.
EdouardIFP
  • 273
  • 2
  • 10
0

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.