Stay Hungry.Stay Foolish.

Windows 平台开发打包 PyQt 程序

安装PyQt5:

pip3 install PyQt5

安装完成之后,在 Python 的安装目录 Lib\site-packages\PyQt5\Qt\bin 有一系列的动态链接库:

PyQt5 的动态链接库

然后你就可以开始基于 PyQt5 的开发了,假设你已经完成开发,启动文件为 app.py

安装 PyWin32

Python 是没有自带访问 Windows 系统 API 的库,需要下载 PyWin32:https://github.com/mhammond/pywin32/releases ,切记下载符合自己系统和 Python 版本的。下载后双击安装即可。

PyWin32

安装 pyinstaller

PyInstaller 是一个十分有用的第三方库,它能够在Windows、Linux、 Mac OS X 等操作系统下将 Python 源文件打包,通过对源文件打包, Python 程序可以在没有安装 Python 的环境中运行,也可以作为一个 独立文件方便传递和管理。

安装很简单:pip3 install pyinstaller

打包

使用 .spec 文件打包,因为 PyInstaller 可能会找不到某些依赖的 DLLs,比如 Scipy,需要按需把 DLLs 文件添加进去。如果打包后运行出现找不到某些包,需要按需在 hiddenimports 中引入。

# -*- mode: python -*-

block_cipher = None
binaries = [('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libansari.R6EA3HQP5KZ6TAXU4Y4ZVTRPT7UVA53Z.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libbanded5x.6BKGRRTVPBAVJDT4GH5L624TGG7GHY5A.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libbispeu.5N2XSD7URZS4WTOSLTOG4DDMA4HGB46U.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libblkdta00.JLIHDEUQQTHWXHJD4RSB7K64MY3MW5DF.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libchkder.6HLXPVTQJEGRZGLI5DFRMNW3SS76BHP6.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libcobyla2.JEGTSUUFJ7DFXWZN5PAYZTTLBDATC4WD.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libdcosqb.K4J3XBR4PEETMRHZICUWW4LXG5UONZ34.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libdcosqb.QRGA36MB6CFHWLQN6ETWARR4M4E6P3C2.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libdcsrch.I2AOPDCXAPDRFNPWY55H5UE7XZSU5CVN.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libdet.NOGBD72WN5257V5IUVJX5OTSKUNCMXCW.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libdfft_sub.XSR6LM5MHOHY2B2UKGGX5QUEZ5CQ3GXW.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libdfitpack.6VKCDGWVRKJSDDBHY5M6TIU325Q2OYHW.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libdgamln.W6VMEJDA4FSVFYNWUZFFDXVA42RE2LKH.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libdop853.6TJTQZW3I3Q3QIDQHEOBEZKJ3NYRXI4B.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libdqag.5PZURQTFDOKUXXPRX2T62WGR2MXTEWOV.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libd_odr.274KI3XBVCSZVOLEKQIK5JG5DSBR4RXO.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\liblbfgsb.7PDZL4UMRHK5WSHTZ37FU6VIAS2TJL3M.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libmvndst.KJP3NEE63DTR5HRJDNPRBMM4LKUW7NWF.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libnnls.5LTQOLAJY5PFO6MOEXWNMRWVFRWHYHKT.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libopenblas.BNVRK7633HSX7YVO2TADGR4A5KEKXJAW.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libslsqp_op.NNY57ZXZ43A4RH3YWFA7BKHP5PC2K3I5.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libspecfun.PT6DS3HUOGYNSXUO4OUKK6ATA7B5KP2K.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libSTOPTEST.5KRDYBNZMYQFZE643B56USATGTWADBAH.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libvode.LAGBAXHW3BZEDUSBW6GOPFZ2GO4ZNPVK.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libwrap_dum.KVYC3VTNZLUEQS3OZP5ODXTWAI7VPGVQ.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\libwrap_dum.SQCFAVDOOVPQY7CIMMOBCYPE262NQTXJ.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\lib_arpack-.3JMFNAMKMAK2FLGU3L5GIZKQWYXGQJL2.gfortran-win_amd64.dll', '.'),
            ('...\\Python\\Python35\\Lib\\site-packages\\scipy\\extra-dll\\lib_blas_su.IGN5CJFPXMHEAINXVOVAR5QAUSJ6WMPQ.gfortran-win_amd64.dll', '.')
            ]

a = Analysis(['app.py'],
             pathex=[
                 '...\\Python\\Python35\\Lib\\site-packages\\PyQt5\\Qt\\bin',
                 'C:\\Users\\lufficc\\PycharmProjects\\xxx'],
             binaries=binaries,
             datas=[],
             hiddenimports=['scipy._lib.messagestream', 'numpy', 'tkinter', 'scipy', 'matplotlib', 'fixtk', 'scipy.signal', 'scipy.signal.bsplines', 'scipy.special', 'scipy.special._ufuncs_cxx',
                        'scipy.linalg.cython_blas',
                        'scipy.linalg.cython_lapack',
                        'scipy.integrate',
                        'scipy.integrate.quadrature',
                        'scipy.integrate.odepack',
                        'scipy.integrate._odepack',
                        'scipy.integrate.quadpack',
                        'scipy.integrate._quadpack',
                        'scipy.integrate._ode',
                        'scipy.integrate.vode',
                        'scipy.integrate._dop', 'scipy._lib', 'scipy._build_utils','scipy.__config__',
                        'scipy.integrate.lsoda', 'scipy.cluster', 'scipy.constants','scipy.fftpack','scipy.interpolate','scipy.io','scipy.linalg','scipy.misc','scipy.ndimage','scipy.odr','scipy.optimize','scipy.setup','scipy.sparse','scipy.spatial','scipy.special','scipy.stats','scipy.version'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
          cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='labelme',
          debug=False,
          strip=False,
          upx=True,
          icon='icon.ico',
          runtime_tmpdir=None,
          console=False)

最后运行 pyinstaller -F app.spec 即可。

⬆️

写的不错,帮助到了您,赞助一下主机费~

扫一扫,用支付宝赞赏
扫一扫,用微信赞赏

暂无评论~~