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 :-).
Problem lies in fact that
cx_freeze
tries to useuic
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 inyour_python_dir\Lib\site-packages\PyQt4\uic
. There are two directories there:port_v2
andport_v3
. Rename the first one, for example toport_v2_
. I think similar problem can occur while using Python2-renamev3
then. Anyway, this will causecx_freeze
to find proper version ofuic
and the script should build correctly.