16

I can't convert ui to py

it's giving this: screenshot

Mel
  • 5,837
  • 10
  • 37
  • 42
  • Possible duplicate of [How to convert .ui to py in windows ?](http://stackoverflow.com/questions/40354127/how-to-convert-ui-to-py-in-windows) – harthart Apr 05 '17 at 07:11

6 Answers6

35

Instead of installing Python packages by hand, I would consider using conda and pip from a recent Anaconda install (https://www.anaconda.com/download/).

After installing Anaconda with python 3.6, open a privileged (Run as Administrator) cmd or git bash and run the following commands:

Installing PyQt5

PyQt5 is the default one for Python 3.6. You can check available packages by running (conda search pyqt)

conda install pyqt

Generating .py file from .ui

python -m PyQt5.uic.pyuic -x [FILENAME].ui -o [FILENAME].py

Importing generated .py on your Python code

Now, suppose that your file is called MainWindow.py, and its type is QMainWindow. This is how you import it on Python

from PyQt5 import QtWidgets
from mainwindow import Ui_MainWindow
import sys

class ApplicationWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(ApplicationWindow, self).__init__()

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)


def main():
    app = QtWidgets.QApplication(sys.argv)
    application = ApplicationWindow()
    application.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()
Danilo Gasques
  • 666
  • 6
  • 16
20

you are using the correct syntax: pyuic5 -x file.ui -o file.py

but you have to make sure that the file.ui is in the same location of your pyuic5.bat

harthart
  • 404
  • 3
  • 13
13
python -m PyQt5.uic.pyuic -x [FILENAME].ui -o [FILENAME].py

This worked for me. Thanks to Danilo Gasques

bocodes
  • 387
  • 1
  • 4
  • 12
4

Sorry for my bad english

  1. You can find file "pyuic5.exe" (For example it is "C:\Python\venv\Scripts\pyuic.exe")
  2. Through the command line go to the folder with the file "needToConvert.ui"
  3. Enter the following command line: C:\Python\venv\Scripts\pyuic.exe needToConvert.ui -o needToConvert.py
Grossmend
  • 186
  • 8
1

What you need is python3.dll file which is missing and you have to place in your python directory

  • Go here (https://winpython.github.io/).
  • Download the version of python you have and also see which bit version
  • Download the zero version and extract it somewhere temporarily
  • In extracted folder search for python3.dll in the search bar
  • Extract where your python setup is and try then it will work
IFfy KhAn
  • 71
  • 2
  • 7
0

Use this .bat file to automatically convert all *.ui files to python files. All you need is:

  1. Save the script below to ui2py.bat file
  2. Edit the file with notepad and specify the pythonPath directory from your PC
  3. Save changes and execute the ui2py.bat file convertor

    @echo off

    rem set the python path set pythonPath=G:\Programming\WinPython-64bit-3.6.3.0Qt5\python-3.6.3.amd64

    echo [START] converting .ui files...

    rem convert all .ui files in current directory for %%i in (*.ui) do (

    rem Display the file name echo %%i -- ui_%%~ni.py

    rem converting %pythonPath%\python.exe -m PyQt5.uic.pyuic -x %%i -o ui_%%~ni.py

    )

    echo [END] converting .ui files...

akushyn
  • 9
  • 1