Results 1 to 5 of 5
  1. #1

    Blender 2.78, Python 3.5.2 and PIL/Pillow

    I'm author of an addon that uses PIL/Pillow. I'm supplying the PIL folder from Pillow for win64, linux64 and macos. Each of these incude some compiled os specific files. I ask users to put the PIL folder in the user scripts folder's sub directory modules.

    I'm then doing 'from PIL import Image' in the addon.
    This works very well and I'm using it without issues on all of the 3 operating systems. It also works great for the vast majority of the addon's users.

    I have a few users for whom importing the Image module fails however (1 x win7 64, 1x win8 64, 1xwin10 64, 1x macos).

    Note, that for these users importing PIL itself works fine, so the module can be found by the blender bundled python without problems and is in the proper location. But importing Image, from PIL, will fail


    Some people are seing:

    ImportError: cannot import name '_imaging'


    others see:

    ImportError: DLL load failed.
    This one comes in two flavors:


    and



    From what I've found by searching, this indicates a version conflict between python and a module, so the module being compiled for the wrong python version. The thing is, all these people use Python 3.5.2 as it is the one bundled with 2.78 and it's also the one I compiled the PIL, I supply, against.

    I can kind of (but not really) reproduce this error by putting a macos PIL or windows PIL in my modules folder on a linux machine. But I've been assured and have confirmed this is not what's happening for those users. They do use the proper PIL for their OS.

    So, just to make sure, I've walked some of these people through a manual installation of PIL/Pillow and asked them to remove the PIL, I supply, from their modules folder. This is to ensure they indeed have the proper PIL for their os installed. I instruct them to:

    1. remove the modules/PIL folder, you don't need it anymore
    2. open 'cmd' as an admin and navigate to the blender installation folder (c:\program files\Blender Foundation\...)
    3. find the 2.78\python\bin folder, you are looking for a file called 'python.exe'
    4. download https://bootstrap.pypa.io/get-pip.py and put it into the bin folder
    5. in cmd, from the bin folder, type 'python.exe get-pip.py'
    6. when done, go one folder up(from bin) and go into the (new) Scripts folder. You are looking for a file called 'pip.exe'
    7. when you've found it, run 'pip.exe install pillow'

    Unfortunately they still get the same error, so I'm now out of my depth and can't help any further.

    I'd appreciate any input on this, especially:

    1. How can it work for the majority, but not for a few others, when they are all using the same blender bundled python?
    2. How does the manual PIL/Pillow installation for their blender bundled python not solve this?
    3. What more can I try?
    Last edited by MACHIN3; 11-May-17 at 06:01.



  2. #2
    This error can also occur if one of the dependencies that the _imaging.pyd (which is just a DLL) links against can not be loaded (or the wrong version is loaded).

    You can use Dependency Walker to see which DLLs it links against and you can also run blender.exe in profiling mode to get a log of how DLLs are loaded (and where the errors are).

    It could be that the Visual C runtime libraries are not in the search path (did you build with the same MSVC version as Blender?). In that case, installing the respective redistributables might help.



  3. #3
    Originally Posted by BeerBaron View Post
    This error can also occur if one of the dependencies that the _imaging.pyd (which is just a DLL) links against can not be loaded (or the wrong version is loaded).

    You can use Dependency Walker to see which DLLs it links against and you can also run blender.exe in profiling mode to get a log of how DLLs are loaded (and where the errors are).

    It could be that the Visual C runtime libraries are not in the search path (did you build with the same MSVC version as Blender?). In that case, installing the respective redistributables might help.
    Incredible advice, I was able to track it down. The reason is a missing vcruntime140.dll

    You mentioning the Visual C Redistributables got me curious, I would have never thought of this. I checked out the windows installation I used for the windows compiled PIL. It had all the Reidstributables from 2008 upwards, including 2015.

    At the same time I had one of the 4 users, report back that he failed to install pip, saying python.exe could not be found, meaning of course he was in the wrong folder when executing 'pip.exe get-pip.py".
    However it led him to install python 3.6 system wide. Which - to my surprise - fixed his issue with importing Image from PIL.

    So I checked out Python 3.6 for windows and it turns out there's a vcruntime140.dll in the zip/installer.
    I've asked one of the other guys to show me the Redistributables he has installed. 2015 was missing. I told him to install it, and this fixed it for him as well.

    Haven't heard back from the macos guy yet, but it looks like this is solved for good for the Windows users.

    Thanks again BeerBaron!
    Last edited by MACHIN3; 11-May-17 at 16:16.



  4. #4
    You mentioning the Visual C Redistributables got me curious, I would have never thought of this. I checked out the windows installation I used for the windows compiled PIL. It had all the Reidstributables from 2008 upwards, including 2015.
    That's actually a pretty common error that people run into. If you install Visual Studio, you'll have the respective runtimes installed, but when you ship it's easy to forget that you need to supply them as well.

    In your case, it would be a good idea to use the same version of MSVC that was used to build Blender 2.78c, which appears to be version 12 (VS2013).

    So I checked out Python 3.6 for windows and it turns out there's a vcruntime140.dll in the zip/installer.
    It turns out that the official versions of Python 3.5/3.6 are built against version 14 (VS2015), but the version shipped with Blender 2.78c is not. Again, this something you can verify with Dependency Walker.

    Some of the buildbot builds are on version 14, so the next version of Blender will probably be on 14, as well.



  5. #5
    Member doakey3's Avatar
    Join Date
    Sep 2011
    Location
    Oregon, United States
    Posts
    127
    Here's how I installed pillow in a test:

    Code:
    bl_info = {
        "name": "My Test Addon",
        "category": "Object"}
        
    def register():
        
        import pip
        pip.main(['install', 'pillow'])
        
        from PIL import Image
        
    def unregister():
        print("Goodbye World")
    You would need to tell your users that they need an internet connection when installing the addon. This also wouldn't work for linux users since you need super user authority to install python modules...
    Last edited by doakey3; 18-May-17 at 12:11.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •