SyntaxError when using cx_freeze on PyQt app

浪尽此生 提交于 2019-12-06 04:07:04

问题


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

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 :-).


回答1:


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:

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.



来源:https://stackoverflow.com/questions/20590113/syntaxerror-when-using-cx-freeze-on-pyqt-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!