在PyQt应用上使用cx_freeze时出现SyntaxError [英] SyntaxError when using cx_freeze on PyQt app

查看:78
本文介绍了在PyQt应用上使用cx_freeze时出现SyntaxError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用PyQt4从Python 3脚本构建.exe文件时,会出现非常烦人的问题。我认为它与使用 uic 模块动态加载 .ui 文件有关。
cx_freeze 返回:

This is quite annoying problem that occurs when trying to build .exe file from Python 3 script using PyQt4. I think it is connected with using uic module for dynamic loading of .ui files. cx_freeze returns:

  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:
                    ^
SyntaxError: invalid syntax

我已经解决了这个问题,但是最近又遇到了。在网络上查找解决方案并不容易,因此我决定在SO上发布问答。希望不仅对我有用:-)。

I have solved this problem some time ago but I have recently encountered it again. Finding solution on the web isn't easy so I decided to post Q&A on SO. Hope it will be helpful not only for me :-).

推荐答案

问题实际上在于 cx_freeze 尝试对Python 2(而非3)使用 uic 子模块,并且在其中一个文件中遇到Py3不兼容的语法。解决方案非常简单:

Problem lies in fact that cx_freeze tries to use uic submodule for Python 2, not 3 and encounters Py3-incompatible syntax in one of files. Solution is quite simple:

查找 uic 目录,它应该位于 your_python_dir\ \库站点包\PyQt4\uic 。那里有两个目录: port_v2 port_v3 。重命名第一个,例如为 port_v2 _ 。我认为使用Python2重命名 v3 时可能会发生类似的问题。无论如何,这将导致 cx_freeze 找到 uic 的正确版本,并且脚本应正确构建。

Find uic directory, it should be located in your_python_dir\Lib\site-packages\PyQt4\uic. There are two directories there: port_v2 and port_v3. Rename the first one, for example to port_v2_. I think similar problem can occur while using Python2-rename v3 then. Anyway, this will cause cx_freeze to find proper version of uic and the script should build correctly.

这篇关于在PyQt应用上使用cx_freeze时出现SyntaxError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆