python桌面应用(pyinstaller打包多个py文件)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python桌面应用(pyinstaller打包多个py文件)相关的知识,希望对你有一定的参考价值。

参考技术A 一 、当写这篇文章的时候,pyinstaller官网版本对pyqt5打包可能会遇到Could not find QtWebEngineProcess.exe.的错误。解决方法为:

二 、如果有报错:“could not find or load the Qt platform plugin "windows" ”。原因之一可能是你把打包后的文件放在了中文目录下。只需要将打包后的文件放在英文目录下,就可以解决。

三、 多文件打包为单一文件时,即pyinstaller 命令中加入了-F,也可能会导致错误。尽量不要使用-F。

使用pyinstaller打包的时候,仅打包.py文件,其余依赖项只需在打包完成后,拷入打包生成的根目录即可。

命令格式如下,下命令为一条命令,为方便显示做了分行处理:

以上文图中结构为例,在根目录打开命令窗口,输入命令:

在目录结构:“程序根目录\dist\main\” 下可以找到生成的main.exe。将其他依赖文件拷贝进入“程序根目录\dist\main\” 下,即可运行。
=========吃鸡、撸码复古键盘=========

Python | 用Pyinstaller打包发布exe应用

参考:https://jingyan.baidu.com/article/a378c960b47034b3282830bb.html

https://ask.csdn.net/questions/720080

https://blog.csdn.net/solarnanocar/article/details/82077484(如果不需要转化成单个exe文件,单单此条即可,亲测有效)

https://www.cnblogs.com/gopythoner/p/6337543.html

https://jingyan.baidu.com/article/bad08e1ed173d409c85121f8.html

需打包程序参考:https://www.cnblogs.com/msxh/p/4966899.html

 

D:\\pythonWorkspace\\test>pyinstaller.exe -F -w testa.py
74 INFO: PyInstaller: 3.4
74 INFO: Python: 3.7.2
75 INFO: Platform: Windows-10-10.0.16299-SP0
76 INFO: wrote D:\\pythonWorkspace\\test\\testa.spec
80 INFO: UPX is not available.
82 INFO: Extending PYTHONPATH with paths
[\'D:\\\\pythonWorkspace\\\\test\', \'D:\\\\pythonWorkspace\\\\test\']
82 INFO: checking Analysis
87 INFO: Building because D:\\pythonWorkspace\\test\\testa.py changed
87 INFO: Initializing module dependency graph...
89 INFO: Initializing module graph hooks...
91 INFO: Analyzing base_library.zip ...
2803 INFO: running Analysis Analysis-00.toc
2806 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by d:\\python\\python.exe
3558 INFO: Caching module hooks...
3563 INFO: Analyzing D:\\pythonWorkspace\\test\\testa.py
3788 INFO: Processing pre-find module path hook   distutils
3820 INFO: Loading module hooks...
3820 INFO: Loading module hook "hook-distutils.py"...
3823 INFO: Loading module hook "hook-encodings.py"...
3908 INFO: Loading module hook "hook-pkg_resources.py"...
4162 INFO: Processing pre-safe import module hook   win32com
4468 INFO: Loading module hook "hook-pydoc.py"...
4469 INFO: Loading module hook "hook-pygame.py"...
4470 WARNING: Hidden import "pygame._view" not found!
4470 INFO: Loading module hook "hook-pythoncom.py"...
4711 INFO: Loading module hook "hook-pywintypes.py"...
4955 INFO: Loading module hook "hook-sysconfig.py"...
4957 INFO: Loading module hook "hook-win32com.py"...
5407 INFO: Loading module hook "hook-xml.py"...
5630 INFO: Looking for ctypes DLLs
5642 INFO: Analyzing run-time hooks ...
5645 INFO: Including run-time hook \'pyi_rth_pkgres.py\'
5648 INFO: Including run-time hook \'pyi_rth_win32comgenpy.py\'
5655 INFO: Looking for dynamic libraries
7280 INFO: Looking for eggs
7281 INFO: Using Python library d:\\python\\python37.dll
7281 INFO: Found binding redirects:
[]
7289 INFO: Warnings written to D:\\pythonWorkspace\\test\\build\\testa\\warn-testa.txt
7344 INFO: Graph cross-reference written to D:\\pythonWorkspace\\test\\build\\testa\\xref-testa.html
7353 INFO: checking PYZ
7356 INFO: Building because toc changed
7357 INFO: Building PYZ (ZlibArchive) D:\\pythonWorkspace\\test\\build\\testa\\PYZ-00.pyz
7953 INFO: Building PYZ (ZlibArchive) D:\\pythonWorkspace\\test\\build\\testa\\PYZ-00.pyz completed successfully.
7960 INFO: checking PKG
7962 INFO: Building because toc changed
7962 INFO: Building PKG (CArchive) PKG-00.pkg
11987 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
11993 INFO: Bootloader d:\\python\\lib\\site-packages\\PyInstaller\\bootloader\\Windows-64bit\\runw.exe
11993 INFO: checking EXE
11994 INFO: Rebuilding EXE-00.toc because testa.exe missing
11995 INFO: Building EXE from EXE-00.toc
11998 INFO: Appending archive to EXE D:\\pythonWorkspace\\test\\dist\\testa.exe
12012 INFO: Building EXE from EXE-00.toc completed successfully.

执行后能在下图路径中的dist文件夹内生成一个exe应用程序,我的是win10系统,经实验,这个应用程序在其他的win10电脑中可以运行,但在win7里不行,若有大神有解决方法,欢迎指点~

 

D:\\pythonWorkspace\\test>pyinstaller -D -w testa.py
71 INFO: PyInstaller: 3.4
71 INFO: Python: 3.7.2
72 INFO: Platform: Windows-10-10.0.16299-SP0
76 INFO: wrote D:\\pythonWorkspace\\test\\testa.spec
82 INFO: UPX is not available.
84 INFO: Extending PYTHONPATH with paths
[\'D:\\\\pythonWorkspace\\\\test\', \'D:\\\\pythonWorkspace\\\\test\']
84 INFO: checking Analysis
109 INFO: checking PYZ
124 INFO: checking PKG
124 INFO: Bootloader d:\\python\\lib\\site-packages\\PyInstaller\\bootloader\\Windows-64bit\\runw.exe
124 INFO: checking EXE
124 INFO: Building because console changed
124 INFO: Building EXE from EXE-00.toc
124 INFO: Appending archive to EXE D:\\pythonWorkspace\\test\\build\\testa\\testa.exe
140 INFO: Building EXE from EXE-00.toc completed successfully.
140 INFO: checking COLLECT
WARNING: The output directory "D:\\pythonWorkspace\\test\\dist\\testa" and ALL ITS CONTENTS will be REMOVED! Continue? (y/n)y
6765 INFO: Removing dir D:\\pythonWorkspace\\test\\dist\\testa
6859 INFO: Building COLLECT COLLECT-00.toc
7280 INFO: Building COLLECT COLLECT-00.toc completed successfully.

执行后,可在上图路径中的dist文件夹内生成一个testa文件夹,经压缩后就可发给他人电脑中运行了,我win10的系统发到win7上可以运行

 

 

如果有你有其他的素材包,得把素材包复制到新生成的文件夹内,本人还不知道如何把素材包一起转化成单一的exe文件,望有路过的大神指点~

 

以上是关于python桌面应用(pyinstaller打包多个py文件)的主要内容,如果未能解决你的问题,请参考以下文章

pyinstaller+wxpython+selinum

Python打包-Pyinstaller

pyinstaller打包Windows的exe文件后,多进程导致程序反复重启,python

pyinstaller打包python应用程序

Python利用multiprocessing实现多进程,Pyinstaller打包python多进程程序出现多个窗口

Pycharm怎么打包Python脚本