当前位置:网站首页>Pycharm项目使用pyinstalle打包过程中问题及解决方案
Pycharm项目使用pyinstalle打包过程中问题及解决方案
2022-06-30 10:19:00 【消灭BUG鸭】
1、下载并安装pyinstaller库
(一)直接命令行安装
pip3 install pyinstaller
(二)或者通过官网下载包,然后本地安装
2、使用pyinstaller命令行进行打包
(一)含有依赖库的整个项目建议使用-D方式,含有打包目录,包括一些dlls应用程序扩展等。先-c有控制台,再-w无需黑窗控制台进行打包,logo.ico为自定义的exe图标,XXXX.py为主程序py文件。即:
先使用下面命令行打包:
pyinstaller -D -c -i logo.ico XXXX.py
在步骤5后,再使用下面隐藏黑窗口的命令行,再次打包:
pyinstaller -D -w -i logo.ico XXXX.py
(二)也可以使用-F进行打包成单独的exe,打包速度比-D慢很多。其余文件意义同(一)
pyinstaller -F -c -i logo.ico XXXX.py ##生成单独exe, -c有控制台黑窗
pyinstaller -F -w -i logo.ico XXXX.py ##生成单独exe,-w无控制台黑窗
3、使用多线程文件进行打包时,需要同时出现多窗口,因此需要在主程序导入multprocessing,即在主程序加入以下语句。
import multiprocessing
.
.
.
if __name__ == "__main__":
####################多线程打包需要在主函数开始处添加
multiprocessing.freeze_support()
4、打包之后,exe在dist文件夹下。出现的问题汇总:
(1)ModuleNotFoundError:No module name “xxx”
原因分析:这是缺少第三方库xxx
解决方法:可以在cmd或者pycharm的Terminal进行直接用pip安装这个库
(2)出现Hidden import not found “xxx”和 WARNING提示
原因分析:不会影响程序的正常运行,可以忽略这个警告
解决方法:忽略即可
(3)黑窗闪退
原因分析:一些库没有安装到或者打包时pyinstaller强行打包了一些不必要的库。
解决方法:打开.exe文件,通过查看命令符窗口报的错来解决。比如::将项目中一些必要的输入文件,配置文件等放入与exe同一级目录下。
5、将运行时出现的问题解决后,删除项目文件夹中的(pycache,build,dist,xxx.spec)文件
6、最后将包含exe文件的dist文件夹压缩成压缩包后,这样就可以到别的电脑中双击运行。
【最后,可以忽略这个,但是目前通过修改打包生成的配置spec已解决】
(1) 打包过程中,WARNING警告提示:
4377 WARNING: lib not found: torch_python.dll dependency of
D:\Software\Anaconda3\Path\envs\Yolov5-DeepSort-Pytorch\lib\site-packages\torch_C.cp38-win_amd64.pyd
4932 WARNING: lib not found: torch_cpu.dll dependency of
D:\Software\Anaconda3\Path\envs\Yolov5-DeepSort-Pytorch\lib\site-packages\torchvision_C.pyd
4936 WARNING: lib not found: c10_cuda.dll dependency of
D:\Software\Anaconda3\Path\envs\Yolov5-DeepSort-Pytorch\lib\site-packages\torchvision_C.pyd
4937 WARNING: lib not found: torch_cuda.dll dependency of
D:\Software\Anaconda3\Path\envs\Yolov5-DeepSort-Pytorch\lib\site-packages\torchvision_C.pyd
4938 WARNING: lib not found: c10.dll dependency of
D:\Software\Anaconda3\Path\envs\Yolov5-DeepSort-Pytorch\lib\site-packages\torchvision_C.pyd
(2) 修改方法
将下面四行插入.spec配置文件:
for d in a.datas:
if '_C.cp38-win_amd64.pyd' in d[0]:
a.datas.remove(d)
break
(3)详细的.spec配置文件:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['main.py'],
pathex=['D:\\Files'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
####################################add
for d in a.datas:
if '_C.cp38-win_amd64.pyd' in d[0]:
a.datas.remove(d)
break
####################################stop
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
在修改完配置文件之后,使用如下命令进行编译exe文件:
pyinstaller mult_car.spec
边栏推荐
猜你喜欢

焕发青春的戴尔和苹果夹击,两大老牌PC企业极速衰败

【STL源码剖析】迭代器

Retest the cloud native database performance: polardb is still the strongest, while tdsql-c and gaussdb have little change

Matplotlib notes: contour & Contour

Dickinson's soul chooses its companion

我在鹅厂淘到了一波“炼丹神器”,开发者快打包

matplotlib 笔记: contourf & contour

再测云原生数据库性能:PolarDB依旧最强,TDSQL-C、GaussDB变化不大

Google 辟谣放弃 TensorFlow,它还活着!

File sharing server
随机推荐
透过华为军团看科技之变(五):智慧园区
Google 辟谣放弃 TensorFlow,它还活着!
How can the sports app keep the end-to-side background alive to make the sports record more complete?
断路器HystrixCircuitBreaker
透過華為軍團看科技之變(五):智慧園區
Input a decimal data, convert to 8, using the sequence stack
Dickinson's soul chooses its companion
CVPR 2022 | Tsinghua & bytek & JD put forward BRT: Bridging Transformer for vision and point cloud 3D target detection
智能DNA分子纳米机器人模型来了
Collectors.toMap应用
Auto SEG loss: automatic loss function design
[proteus simulation] Arduino uno led simulated traffic light
SGD has many improved forms. Why do most papers still use SGD?
05_ Node JS file management module FS
Musk has more than 100 million twitter fans, but he has been lost online for a week
Machine learning interview preparation (I) KNN
Pytorch notes: validation, model eval V.S torch. no_ grad
Anhui "requirements for design depth of Hefei fabricated building construction drawing review" was printed and distributed; Hebei Hengshui city adjusts the pre-sale license standard for prefabricated
Collectors. Tomap application
Skill sorting [email protected]+adxl345+ Motor vibration + serial port output