Python Forum
Convert .ui file .py
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert .ui file .py
#1
Hi

I am experiencing an issue regarding to convert an .ui file to .py.

I am running QT Designer 3.6 with PyQt5. I have tried the below commands for converting but I still cannot get it right.

C:\Python35\Lib\site-packages\PyQt5>pyuic5 -o FirstApp.py FirstApp.ui
C:\Python35\Lib\site-packages\PyQt5>pyuic5 -o FirstApp.ui FirstApp.py
C:\Python35\Lib\site-packages\PyQt5>pyuic5 -x FirstApp.ui -o FirstApp.py
C:\Python35\Lib\site-packages\PyQt5>pyuic5.bat -x FirstApp.ui -o FirstApp.py
C:\Python35\Lib\site-packages\PyQt5>pyuic5.bat --execute FirstApp.ui -o FirstApp.py
C:\Python35\Lib\site-packages\PyQt5>pyuic5.bat --execute FirstApp.ui --output FirstApp.py

When I check in the folder PyQt5, there is only .ui file and the .py is not created. Can someone please help with this issue.

Kind regards
Mpho
Reply
#2
You need to find where pyuic5.exe is. Probably in C:\Python36\Scripts\
Then if that's where it is I think you need to do :
C:\Python36\Scripts\pyuic5.exe -o FirstApp.ui FirstApp.py
Reply
#3
Quick test,with use of virtual environment.
C:\1
λ python -m venv pyqt_5
λ cd pyqt_5
λ C:\1\pyqt_5\Scripts\activate.bat

# Environment is active,install into it
(pyqt_5) C:\1\pyqt_5\Scripts
λ pip install PyQt5
# pyqt5-tools for designer 
λ pip install pyqt5-tools
I start designer.exe
C:\1\pyqt_5\Lib\site-packages\pyqt5-tools\designer.exe
I save my test.ui in C:\1\pyqt_5\Scripts
So now is test.ui and pyuic5.exe in same folder.
Test and app.py is made correct.
(pyqt_5) C:\1\pyqt_5\Scripts
λ pyuic5.exe test.ui -o app.py
Reply
#4
I do not have pyuic5.exe, do I need to this file?

And I also do not have \Scripts\ (folder).
Reply
#5
(Jul-16-2017, 08:01 PM)mailal Wrote: I do not have pyuic5.exe, do I need to this file?

And I also do not have \Scripts\ (folder).

Well how sure are you that you don't have it. It could be somewhere else on your system and if it's not in your PATH it will not run unless you give the full path to it.
Reply
#6
(Jul-16-2017, 08:01 PM)mailal Wrote: And I also do not have \Scripts\ (folder).
All Python installation on Windows shall have a Scripts folder.
It's C:\Python35\Scripts for 3.5.

Quote:I do not have pyuic5.exe, do I need to this file?
It may be different on how you install,you should use pip(version-9) as do in demo.
You see usage of pip last in this tutorial.
pip install PyQt5
# pyqt5-tools for designer 
pip install pyqt5-tools
Reply
#7
@mailal: Why do you want to convert *.ui-files? You can dynamically load the *.ui-files by using the uic in PyQt5.

Example:
from PyQt5 import uic, QtWidgets
import sys

class Ui(QtWidgets.QDialog):
    def __init__(self):
        super(Ui, self).__init__()
        uic.loadUi('SomeUi.ui', self)
        self.show()

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = Ui()
    sys.exit(app.exec_())
Reply
#8
I have an this error:Error: Permission denied:
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020