3

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!

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
a.ras2002
  • 385
  • 2
  • 7
  • 21

6 Answers6

6

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
ILYAS_Kerbal
  • 1,369
  • 11
  • 18
  • Thanks it works perfectly! What i was missing is the pyuic5 command, I was using pyuic all the time without the 5.. – a.ras2002 Jan 08 '17 at 16:24
5

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.

crx
  • 153
  • 2
  • 8
4

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
kenjii himura
  • 193
  • 1
  • 1
  • 10
2

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"
Unheilig
  • 16,196
  • 193
  • 68
  • 98
karthi k
  • 21
  • 2
1

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

works

GonzaloV
  • 11
  • 1
1

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"

Ju Mo
  • 11
  • 5