pyinstaller安装及使用

  1. 命令行->pip install pyinstaller
  2. test.py与text.txt放在同一个目录底下,生成spec文件:pyi-makespec test.py (一个文件夹)

  3. block_cipher = None
    a = Analysis(['test.py'],
                 pathex=['/home/lixin/test'],
                 binaries=[],
                 datas=[('test.txt','.')], ## <---- 修改此处添加外部文件
                 hiddenimports=[],
                 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='test',
              debug=False,
              strip=False,
              upx=True,
              runtime_tmpdir=None,
              console=True )

  3.打包:pyinstaller test.spec 此时生成两个文件夹,build以及dist,dist中的test文件夹即为发布的文件夹.

打包PYQT5的注意事项

  1. 打包过程中会提示在某个目录下缺少文件,我的路径是C:\qt64\qt_1544645195969\_h_env\Library\plugins\pyqt5qmlplugin.dll ,把C:\Anaconda3\Library\plugins\PyQt5下的这个文件复制到错误提示的路径即可.
  2. pyqt5打包成exe 缺少 "windows" 插件.复制 C:\QT\Tools\QtCreator\bin\plugins\platforms目录到项目所在目录,

  3. 使用pyinstaller打包时,要把这个目录一起打进去.  .spec文件:  datas=[('platforms','platforms')],

打包命令:

  1. pyi-makespec test.py
  2. 需要添加文件的话修改.spec文件
  3. pyinstaller test.spec

猜你喜欢

转载自www.cnblogs.com/xuyuchen/p/10247435.html