3

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.

2
  • Works fine for me. Obviously there is something wrong with your ui file - but since you didn't provide it, there's not much more that can be said. Commented Jul 13, 2016 at 17:11
  • You should check if the same file can be converted in the regular way using pyuic4 in the command line. If it doesn't work there either, your .ui file is the problem. Commented Jul 14, 2016 at 6:33

2 Answers 2

5

This error popped because my .ui file was not saved with the recent changes that i had done. The file name showed the asterisk(*) mark in the file name. Once i saved the file with changes it could be converted into a .py file.

Sign up to request clarification or add additional context in comments.

Comments

0

Thanks to ekhumoro and mwormser. The problem was indeed the .ui file. I retried it with a new .ui file and everything worked fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.