Pyinstaller with PIL. ImportError: cannot import n

2019-07-13 12:33发布

I am having trouble running a compiled executable that includes pillow. I have used pyinstaller which seems to compile well enough, however after running the exe, an error is thrown. Seems there is a conflict with '_imaging' being referenced instead of 'Image'.

First off, I find it strange how pillow installs to a PIL directory rather than a pillow and the modules are also referenced as PIL. I doubt that has anything to do with the problem though.

There isn't actually a _imaging.py file in Python27\Lib\site-packages\PIL however and I suspect this might be a problem as somehow pyinstaller has made the executable require it. Not sure if there is some way to exclude it from the build. This may be a next step.

Issues like this and thishave been raised but not solved. Some also refer to PIL not being uninstalled before installing pillow, but PIL is definitely uninstalled and I have tried both binaries and pip installs of pillow.

Any suggestions?

Error from runtime:

Traceback (most recent call last):
  File "<string>", line 26, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\PIL.PngImagePlugin", line 40, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\PIL.Image", line 63, in <module>
ImportError: cannot import name _imaging

Extract from the PIL.Image file is below and the offending line is

from PIL import _imaging as core

try:
    # If the _imaging C module is not present, Pillow will not load.
    # Note that other modules should not refer to _imaging directly;
    # import Image and use the Image.core variable instead.
    # Also note that Image.core is not a publicly documented interface,
    # and should be considered private and subject to change.
    from PIL import _imaging as core
    if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
        raise ImportError("The _imaging extension was built for another "
                          " version of Pillow or PIL")

from PIL import Image

And this is how I am calling pillow from my script:

from PIL import Image

0条回答
登录 后发表回答