Pyinstaller .exe cannot find _tiffile module - Loading of some compressed images will be very slow

前端 未结 4 1714
面向向阳花
面向向阳花 2020-12-20 21:12

When I run my code from Pyinstaller the tiff reader works fine. After freezing using Pyinstaller I get the following warning:

UserWarning: ImportErr         


        
4条回答
  •  萌比男神i
    2020-12-20 22:01

    From inspecting the code, tifffile.py seems to be looking for a module called _tifffile, which presumably is the expected name of the compiled C extension:

    try:
        if __package__:
            from . import _tifffile
        else:
            import _tifffile
    except ImportError:
        warnings.warn(
            "ImportError: No module named '_tifffile'. "
            "Loading of some compressed images will be very slow. "
            "Tifffile.c can be obtained at http://www.lfd.uci.edu/~gohlke/")
    

    The tifffile.cpython-35.pyc is just the bytecode generated from tiffile.py. You don't need to bother with that one.

    The .c file alone won't help you, either. It needs to be compiled to to create a usable Python extension, which needs to be named something like _tiffile.cp35-win_amd64.pyd (can vary depending on your system and python version/installation) so it can be used by import _tifffile.

    Compiling can be a daunting task if you have not done this before. If you feel you are up to it, the Python documentation can help you get started. You will need to have the same Compiler and settings that your Python version was compiled with.

    However, there may be a simpler solution. If your code works fine before freezing, chances are you have the compiled extension correctly installed on your system. Pyinstaller probably misses it because it can find tifffile.py and is satisfied. Look for the correct .pyd file in your Python directories and see if you can modify the .spec file Pyinstaller created for your project, where you specify to include the .pyd file.

提交回复
热议问题