I can't convert ui to py
it's giving this:
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()
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
python -m PyQt5.uic.pyuic -x [FILENAME].ui -o [FILENAME].py
This worked for me. Thanks to Danilo Gasques
Sorry for my bad english
What you need is python3.dll file which is missing and you have to place in your python directory
Use this .bat file to automatically convert all *.ui files to python files. All you need is:
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...