I am trying to write a program in python that will convert a .ui file in the same folder (created in Qt Designer) into a .py file. This is the code for this extremely basic program:
# -*- coding: utf-8 -*-
from PyQt4 import uic
with open('exampleinterface.py', 'w') as fout:
uic.compileUi('exampleinterface.ui', fout)
It gives the following error (with long path names shortened):
Traceback (most recent call last):
File "", line 1, in
File "...\Python32_3.5\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile execfile(filename, namespace)
File "...\Python32_3.5\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 88, in execfile exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace) File ".../Documents/Python/UiToPy/minimalconvert.py", line 11, in uic.compileUi('exampleinterface.ui', fout)
File "...\Python32_3.5\lib\site-packages\PyQt4\uic__init__.py", line 173, in compileUi winfo = compiler.UICompiler().compileUi(uifile, pyfile, from_imports, resource_suffix)
File "...\Python32_3.5\lib\site-packages\PyQt4\uic\Compiler\compiler.py", line 140, in compileUi w = self.parse(input_stream, resource_suffix)
File "...\Python32_3.5\lib\site-packages\PyQt4\uic\uiparser.py", line 974, in parse document = parse(filename)
File "...\Python32_3.5\lib\xml\etree\ElementTree.py", line 1182, in parse tree.parse(source, parser)
File "...\Python32_3.5\lib\xml\etree\ElementTree.py", line 594, in parse self._root = parser._parse_whole(source) xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 1
Can anyone tell me why this isn't working, and if there is a solution?
Note: I know that there are other ways to convert a .ui file into a .py file, but I am looking for one that I can easily integrate into a python program, without calling an outside file.
Thanks to ekhumoro and mwormser. The problem was indeed the .ui file. I retried it with a new .ui file and everything worked fine.