PyInstaller, spec file, ImportError: No module named 'blah'

前端 未结 3 1883
走了就别回头了
走了就别回头了 2020-12-01 09:43

I am trying to build a python script via PyInstaller. I have used the following commands to configure, generate a spec file, and build:

wget pyinstaller.zip         


        
3条回答
  •  庸人自扰
    2020-12-01 10:28

    The problem is that pyinstaller won't see second level imports. So if you import module A, pyinstaller sees this. But any additional module that is imported in A will not be seen.

    There is no need to change anything in your python scripts. You can directly add the missing imports to the spec file. Just add the following in a = Analysis(...):

    hiddenimports=["mysql"],
    

    This should be the result:

    a = Analysis([os.path.join(HOMEPATH,'support/_mountzlib.py'), os.path.join(HOMEPATH,'support/useUnicode.py'), 'icinga.py'],
             pathex=['/home/user/projects/icinga_python/releases/v2.1'], hiddenimports=["mysql"],)
    

    After that run pyinstaller with the spec file as an argument.

提交回复
热议问题