Error: Could not find or load the Qt platform plugin “windows” - PyQt + Pyinstaller

后端 未结 3 1678
天命终不由人
天命终不由人 2021-02-20 11:58

I am trying to bundle a PyQt project using Pyinstaller. I tried creating package using command pyinstaller --onedir Hello.py.

This creates dist folder and h

3条回答
  •  鱼传尺愫
    2021-02-20 12:35

    I wrote a similar answer to the same question as I have been struggling with this issue too. Just like you I tried to set the environment path and copy the folder (which worked but again it has to be done manually. If you look at the top of your generated .spec file you'll see mode: python so that gave me an idea as you can see below:

    # -*- mode: python ; coding: utf-8 -*-
    
    block_cipher = None
    
    pf_foldr='C:\\Users\\Gabryxx7\\anaconda3\\envs\\\\Library\\plugins\\platforms\\'
    
    a = Analysis(['C:\\Users\\Gabryxx7\\PycharmProjects\\\\program.py'],
                 pathex=['C:\\Users\\Gabryxx7\\PycharmProjects\\\\'],
                 binaries=[(pf_foldr+'qwindows.dll', 'platforms\\qwindows.dll'),
                 (pf_foldr+'qdirect2d.dll', 'platforms\\qdirect.dll'),
                 (pf_foldr+'qoffscreen.dll', 'platforms\\qoffscreen.dll'),
                 (pf_foldr+'qwebgl.dll', 'platforms\\qwebgl.dll')
                 ],
                 datas=[],
                 hiddenimports=['GUI', 'API', 'Threading', 'ssl', 'pyodbc'],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher,
                 noarchive=False)
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,
              [],
              name='programName',
              debug=False,
              bootloader_ignore_signals=False,
              strip=False,
              upx=True,
              upx_exclude=[],
              runtime_tmpdir=None,
              console=True ) # False to avoid the console
    

    This is a sample for a --one-file spec. As it says on the docs: https://pyinstaller.readthedocs.io/en/stable/spec-files.html

    In one-file mode, there is no call to COLLECT, and the EXE instance receives all of the scripts, modules and binaries.

    While for the binaries, each binary should be a tuple with two values:

    The first string specifies the file or files as they are in this system now. The second specifies the name of the folder to contain the files at run-time.

提交回复
热议问题