关于Py2exe对Pyqt5.uic报错的解决 | Blurred code

关于Py2exe对Pyqt5.uic报错的解决

panda

2016/03/05

LastMod:2020/03/22

Categories: Python

先上代码


from distutils.core import setup
import py2exe
import sys

#this allows to run it with a simple double click.
sys.argv.append('py2exe')

py2exe_options = {
"includes": ["sip",'mainwindow.h'],
#"excludes":['PyQt5.uic'],
"dll_excludes": ["MSVCP90.dll",],#排除此文件
"compressed": 1,
"optimize": 2,
"ascii": 0,
"bundle_files": 1,
}

setup(
name = 'sample',
version = '1.0',
windows = ['gui.py'],
data_files=[("",
[r"C:\Python34\Lib\site-packages\PyQt5\libEGL.dll"]),
("platforms",
[r"C:\Python34\Lib\site-packages\PyQt5\plugins\platforms\qwindows.dll"])],
zipfile = None,
options = {'py2exe': py2exe_options}
)

把该文件编写为test.py,然后进行打包,出现若干问题。

1.出现如下问题 File "E:\Python32_32\lib\site-packages\cx_Freeze\finder.py", line 366, in _LoadModule module.code = compile(codeString, path, "exec") File "E:\Python32_32\lib\site-packages\PyQt4\uic\port_v2\load_plugin.py", line 41 except Exception, e:

原因分析:在之前的文章利用uic qtcreator快速创建GUI的文章中,调用了pyqt5.uic模块,但是这个模块有2.X 和3.x版本,在打包过程中会错误调用2.X导致出错。 解决办法,进入python安装目录,\Lib\site-packages\PyQt4\uic,有port_v2 and port_v3.两个文件夹,把Portv2重命名掉。