pyinstaller打包exe

安装

pip install pyinstaller

使用

pyinstaller -F -w xxx.py(加“-F”参数会直接打包成一个exe,加-w会使得运行时没有黑窗doc窗口)

问题及解决

1. 很多WARN,提示lib not found

一般来说,好像不会有什么问题

2. ImportError: numpy.core.multiarray failed to import

numpy的版本问题,pip list看一下版本,1.16的,重装了1.15的(pip install numpy==1.15.4)

3. OSError: [WinError 126] 找不到指定的模块……PyInstallerImportError: Failed to load dynlib/dll……

程序中使用了ctypes,调用了自己c++写的一个dll,那个dll又调用了第三方dll。
报错是因为找不到该dll的第三方依赖了
解决办法,在spec文件中 data处添加附加的dll

附加dll和图标等信息的方式可参考 https://blog.csdn.net/xinyingzai/article/details/80282856或者百度经验中也有修改spec文件的,有详细介绍一些参数格式

4. 有时候会碰到问题,需要更新setuptools,装win32com相关的

‘str’ object has no attribute ‘items’: pip install -U --pre setuptools

RecursionError: maximum recursion depth exceeded

解决方式,在spec文件头添加
import sys
sys.setrecursionlimit(5000)
进行限制


版权声明:本文为ZhangDanzhu原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。