Convert .ui file to .py file using Anaconda

18.5k views Asked by At

Hi maybe this is a stupid question but I can't find the error or what should I do to do this...

I have a .ui file with my GUI designed on QT Designer, and I want to use it with Python. I have installed Anaconda 2 (Python 2.7) and Python 3.6, but when I run the command in the folder where pyuic.py is (C:\Python36\Lib\site-packages\PyQT5\uic)

python pyuic.py -o mainwindow.ui 

I have the following error

Traceback (most recent call last):
File "pyuic.py", line 28, in <module>
from .driver import Driver
ModuleNotFoundError: No module named '__main__.driver'; '__main__' is not a package

Anyone could tell me why and how can I solve it??

Thanks in advance!

6

There are 6 answers

1
ILYAS_Kerbal On BEST ANSWER

Personally, I do it manually Open the terminal and navigate to the directory containing your .ui file.

For PyQt5:

pyuic5 -x example.ui -o example.py

for PyQt4:

pyuic4 -x example.ui -o example.py
0
kenjii himura On

To convert .ui to .py, I do the following :

I use python 3.4 QT5, so the correct command is:

pyuic5 -x gui.ui -o gui.py

Where gui is your file name.

0
GonzaloV On

C:\ProgramData\Anaconda3\python -m PyQt5.uic.pyuic -x "C:\dialog1.ui" -o "C:\dialog1.py"

works

0
karthi k On

This one works for me on my Windows 10 machine

C:\ProgramData\Anaconda3\python -m PyQt5.uic.pyuic -x "C:\dialog1.ui" -o "C:\dialog1.py"
0
Ju Mo On

On my side I opened the cmd windows from ananconda directly. Navigated to the folder (with cd) containing the .ui file. Then I used the command:

C:\.... \python -m PyQt5.uic.pyuic -x "test.ui" -o "test.py"

0
crx On

I had the same Error. I guess the anwers above refer to Linux?

On Windows 7 entering the following line in CMD worked for me:

C:\ProgramData\Anaconda3\python -m PyQt5.uic.pyuic -x "C:\dialog1.ui" -o "C:\dialog1.py"

Notice that there is no path of pyuic. It is called as a class member.