带有 Reportlab 的 PyQt5 项目对 Pyinstaller 有问题
Posted
技术标签:
【中文标题】带有 Reportlab 的 PyQt5 项目对 Pyinstaller 有问题【英文标题】:PyQt5 project with Reportlab having issue for Pyinstaller 【发布时间】:2020-07-30 18:42:13 【问题描述】:我有一个使用 Reportlab 的项目,它在我的调试模式下完美运行。 但是,当我尝试使用 Pyinstaller 制作可执行文件时,它一直说“无法执行脚本”
当我删除 Reportlab 部分并制作 exe 文件时,它运行良好,所以我知道 Reportlab 是问题所在。我一直在阅读有关此问题的所有相关帖子,并且我知道 reportlab 需要更多额外的步骤。我将以下内容用于 pyinstaller
pyinstaller -F --noconsole IMS.py
我想我已经尝试了一切。我已经创建了 reportlab 钩子和所有内容,包括 Fontdata(似乎其他人都用这个解决方案解决了他们的问题https://www.pythoncentral.io/pyinstaller-package-python-applications-windows-mac-linux/)。没有隐藏的导入错误。以下是我的脚本
2094 INFO: PyInstaller: 3.6
2094 INFO: Python: 3.7.3
2095 INFO: Platform: Windows-10-10.0.18362-SP0
2108 INFO: wrote C:\Users\Bruce Ko\Desktop\Minsub Lee\Development\Git\Inventory Software\IMS.spec
2117 INFO: UPX is not available.
2175 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Bruce Ko\\Desktop\\Minsub Lee\\Development\\Git\\Inventory '
'Software',
'C:\\Users\\Bruce Ko\\Desktop\\Minsub Lee\\Development\\Git\\Inventory '
'Software']
2175 INFO: checking Analysis
2176 INFO: Building Analysis because Analysis-00.toc is non existent
2177 INFO: Initializing module dependency graph...
2183 INFO: Caching module graph hooks...
2691 INFO: Analyzing base_library.zip ...
14393 INFO: Caching module dependency graph...
14528 INFO: running Analysis Analysis-00.toc
14604 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\bruce ko\appdata\local\programs\python\python37\python.exe
14917 INFO: Analyzing C:\Users\Bruce Ko\Desktop\Minsub Lee\Development\Git\Inventory Software\IMS.py
21680 INFO: Processing pre-find module path hook distutils
21713 INFO: distutils: retargeting to non-venv dir 'c:\\users\\bruce ko\\appdata\\local\\programs\\python\\python37\\lib'
25019 INFO: Processing pre-find module path hook site
25052 INFO: site: retargeting to fake-dir 'c:\\users\\bruce ko\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\PyInstaller\\fake-modules'
29141 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
47506 INFO: Processing module hooks...
47507 INFO: Loading module hook "hook-Crypto.py"...
47902 INFO: Loading module hook "hook-distutils.py"...
47905 INFO: Loading module hook "hook-encodings.py"...
48204 INFO: Loading module hook "hook-lib2to3.py"...
48441 INFO: Loading module hook "hook-numpy.core.py"...
50951 INFO: Loading module hook "hook-numpy.py"...
50968 INFO: Loading module hook "hook-PIL.Image.py"...
52384 INFO: Loading module hook "hook-PIL.py"...
52401 INFO: Import to be excluded not found: 'FixTk'
52402 INFO: Import to be excluded not found: 'PyQt4'
52402 INFO: Excluding import 'PyQt5'
52405 INFO: Removing import of PyQt5.QtCore from module PIL.ImageQt
52405 INFO: Removing import of PyQt5.QtGui from module PIL.ImageQt
52406 INFO: Excluding import 'tkinter'
52408 INFO: Removing import of tkinter from module PIL.ImageTk
52409 INFO: Import to be excluded not found: 'PySide'
52410 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
52428 INFO: Excluding import 'tkinter'
52429 INFO: Import to be excluded not found: 'FixTk'
52430 INFO: Loading module hook "hook-pkg_resources.py"...
53355 INFO: Processing pre-safe import module hook win32com
53697 INFO: Excluding import '__main__'
53699 INFO: Removing import of __main__ from module pkg_resources
53700 INFO: Loading module hook "hook-pycparser.py"...
53735 INFO: Loading module hook "hook-pydoc.py"...
53750 INFO: Loading module hook "hook-PyQt5.py"...
56023 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
56298 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
56905 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
57853 INFO: Loading module hook "hook-PySide2.py"...
61694 INFO: Loading module hook "hook-PySide2.QtCore.py"...
62052 INFO: Loading module hook "hook-PySide2.QtGui.py"...
62782 INFO: Loading module hook "hook-PySide2.QtNetwork.py"...
66080 INFO: Loading module hook "hook-pythoncom.py"...
67511 INFO: Loading module hook "hook-pywintypes.py"...
68004 INFO: Loading module hook "hook-reportlab.graphics.barcode.py"...
68547 INFO: Loading module hook "hook-reportlab.lib.utils.py"...
68575 INFO: Loading module hook "hook-reportlab.pdfbase.py"...
68606 INFO: Loading module hook "hook-reportlab.pdfbase._fontdata.py"...
68858 INFO: Loading module hook "hook-reportlab.py"...
68860 INFO: Loading module hook "hook-scipy.py"...
68932 INFO: Loading module hook "hook-setuptools.py"...
70016 INFO: Loading module hook "hook-sqlite3.py"...
70242 INFO: Loading module hook "hook-sysconfig.py"...
70277 INFO: Loading module hook "hook-win32com.py"...
71464 INFO: Loading module hook "hook-xml.dom.domreg.py"...
71497 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
71505 INFO: Loading module hook "hook-xml.py"...
71508 INFO: Loading module hook "hook-_tkinter.py"...
72087 INFO: checking Tree
72088 INFO: Building Tree because Tree-00.toc is non existent
72089 INFO: Building Tree Tree-00.toc
72526 INFO: checking Tree
72526 INFO: Building Tree because Tree-01.toc is non existent
72528 INFO: Building Tree Tree-01.toc
72679 INFO: Looking for ctypes DLLs
72730 INFO: Analyzing run-time hooks ...
72738 INFO: Including run-time hook 'pyi_rth_pkgres.py'
72791 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
72820 INFO: Including run-time hook 'pyi_rth_pyside2.py'
72848 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
72876 INFO: Including run-time hook 'pyi_rth_pyqt5.py'
72914 INFO: Looking for dynamic libraries
84296 INFO: Looking for eggs
84296 INFO: Using Python library c:\users\bruce ko\appdata\local\programs\python\python37\python37.dll
84298 INFO: Found binding redirects:
[]
84316 INFO: Warnings written to C:\Users\Bruce Ko\Desktop\Minsub Lee\Development\Git\Inventory Software\build\IMS\warn-IMS.txt
84508 INFO: Graph cross-reference written to C:\Users\Bruce Ko\Desktop\Minsub Lee\Development\Git\Inventory Software\build\IMS\xref-IMS.html
84628 INFO: checking PYZ
84629 INFO: Building PYZ because PYZ-00.toc is non existent
84631 INFO: Building PYZ (ZlibArchive) C:\Users\Bruce Ko\Desktop\Minsub Lee\Development\Git\Inventory Software\build\IMS\PYZ-00.pyz
86508 INFO: Building PYZ (ZlibArchive) C:\Users\Bruce Ko\Desktop\Minsub Lee\Development\Git\Inventory Software\build\IMS\PYZ-00.pyz completed successfully.
86553 INFO: checking PKG
86554 INFO: Building PKG because PKG-00.toc is non existent
86555 INFO: Building PKG (CArchive) PKG-00.pkg
135959 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
135968 INFO: Bootloader c:\users\bruce ko\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
135968 INFO: checking EXE
135969 INFO: Building EXE because EXE-00.toc is non existent
135970 INFO: Building EXE from EXE-00.toc
136048 INFO: Appending archive to EXE C:\Users\Bruce Ko\Desktop\Minsub Lee\Development\Git\Inventory Software\dist\IMS.exe
137633 INFO: Building EXE from EXE-00.toc completed successfully.
这是我执行程序得到的。
第 2 行包括导入 PyQt5
import sys
from PyQt5.QtCore import *
from PyQt5 import QtWidgets
但奇怪的是,当我不包括 reportlab 时,我没有得到这个... 请帮助我,让我摆脱这种痛苦。
我正在使用
Python3.7 PyQt5我曾尝试使用 cx_Freeze,但它让我出现 PyQt5 错误,我不知道为什么.. py2exe 与 python3.7 存在兼容性问题,因此无济于事..
【问题讨论】:
【参考方案1】:经过几天的搜索和研究,我从查询中找到了自己。 从下面可以看出,PyQt5.QtCore 和 QtGui 被模块名称 PIL.ImageQt 删除。
52402 INFO: Excluding import 'PyQt5'
52405 INFO: Removing import of PyQt5.QtCore from module PIL.ImageQt
52405 INFO: Removing import of PyQt5.QtGui from module PIL.ImageQt
这个应用程序不需要任何 PIL.ImageQt 模块。所以改变了我对 Pyinstaller 的命令如下:
pyinstaller -F --noconsole --exclude-module PIL.ImageQt IMS.py
这排除了 PIL.ImageQt 包并且有效!
【讨论】:
以上是关于带有 Reportlab 的 PyQt5 项目对 Pyinstaller 有问题的主要内容,如果未能解决你的问题,请参考以下文章
Python:如何使 Reportlab 在 PDF 输出中移至下一页