PyInstaller failing to include some modules from C:\Python27\Lib

前端 未结 3 1828
野趣味
野趣味 2021-02-06 11:40

I\'ve been repeatedly making good PyInstaller executables of a Tkinter utility program, and suddenly this morning the resulting executable fails with a \"can\'t import\" error f

相关标签:
3条回答
  • 2021-02-06 12:17

    I encounter similar issues while packaging a Python script imported openpyxl. Here is my solution.

    Step 1: install the python module, openpyxl

    $ wine python.exe Scripts/pip.exe install openpyxl
    

    Step 2: add the openpyxl path

    Append the openpyxl path (~/.wine/drive_c/Python27/Lib/site-packages) to pathex in the Analysis object in the application spec file (e.g.,ProcessSpreadsheet.spec).

    a = Analysis(['ProcessSpreadsheet.py'],
                 pathex=['C:\\Python27\\Scripts', '~/.wine/drive_c/Python27/Lib/site-packages'],
                 binaries=None,
                 datas=None,
                 hiddenimports=[],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher)
    

    Step 3: rebuild

    $ wine pyinstaller.exe ProcessSpreadsheet.spec
    

    Refer to here for the detailed description.

    0 讨论(0)
  • 2021-02-06 12:25

    For unix/linux users, make sure the that you are referencing the same packages when compiling as the application do. This issue mainly occurs when using a virtual environment. For that purpose spot the installed package folder and edit the myapp.spec. Then run

    pyinstaller myapp.spec
    
    0 讨论(0)
  • 2021-02-06 12:41

    Found a fix, if not the cause. Here's my updated build line:

    pyinstaller --hidden-import=timeit --hidden-import=bisect -F MyMainModule.py
    

    Still not sure why PyInstaller suddenly forgot how to find these two modules (and only these two modules) among over 20 other modules correctly included in the build.

    0 讨论(0)
提交回复
热议问题