Reputation: 3802
I want to compile uic to PySide6 but I don't find how to install pyside6-uic tool. Where can I install pyside6-uic? I downloaded PySide6 but command pyside6-uic doesn't work.
There is a reference here in the title:
Upvotes: 3
Views: 21127
Reputation: 121
You can do it in the following way.
If pyside6 is installed globally
uic -g python form.ui > ui_form.py
You can find more information on: https://doc.qt.io/qt-6/designer-using-a-ui-file-python.html
Upvotes: 1
Reputation: 1007
I could solve this issue to add this Path to my %PATH% Variable on windows.
C:\Users\<YOUR_USER_PATH_NAME>\AppData\Roaming\Python\Python311\Scripts
Upvotes: 1
Reputation: 86
Step 1. If you installed PySide6
a. In a venv then go to your venv's folder.
b. Globally then go to your python installation folder.
Step 2. Go to Lib then site-packages then PySide6.
Step 3. Copy uic.exe ( or uic if the file extension are hidden) create a folder called bin and paste what you've copied inside it.
To compile ui files from:
QtDesigner: From the top menu select Form -> View Python Code... then click on the save icon (floppy disk) from the newly opened window.
Command Prompt: pyside6-uic.exe mainwindow.ui > ui_mainwindow.py
PowerShell: pyside6-uic.exe mainwindow.ui -o ui_mainwindow.py
Upvotes: 5
Reputation: 260
The pyside6-uic
tool is supposed to be installed automatically when installing the Python package.
uic
is in PATHWhen using loadUiType
, the Qt documentation (here) states that :
The internal process relies on uic being in the PATH. The pyside6-uic wrapper uses a shipped uic that is located in the site-packages/PySide6/uic, so PATH needs to be updated to use that if there is no uic in the system.
But even then, I got the following error :
Cannot run 'pyside6-uic': "execvp: No such file or directory" -
Exit status QProcess::NormalExit ( 255 )
Check if 'pyside6-uic' is in PATH
For me, pyside6-uic
was not located in site-packages/PySide6/uic
. When reinstalling the module with pip
, I noticed this message :
WARNING: The scripts pyside6-assistant, pyside6-designer, pyside6-genpyi,
pyside6-linguist, pyside6-lrelease, pyside6-lupdate, pyside6-rcc and pyside6-uic are
installed in '/Users/<user>/Library/Python/3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning,
use --no-warn-script-location.
So make sure to add the right directory to your $PATH
variable.
Once it's done, you will be able to use the pyside6-uic
command to generate a Python class from a UI file :
pyside6-uic mainwindow.ui > ui_mainwindow.py
You can also load a .ui
file from your code using either:
loadUiType
(doc page) :This function generates and loads a .ui file at runtime, and it returns a tuple containing the reference to the Python class, and the base class.
QUiLoader
(doc page):enables standalone applications to dynamically create user interfaces at run-time using the information stored in UI files or specified in plugin paths
from PySide6.QtUiTools import QUiLoader
ui_file = QFile("mainwindow.ui")
ui_file.open(QFile.ReadOnly)
loader = QUiLoader()
window = loader.load(ui_file)
window.show()
Generally speaking, use absolute paths to access your UI files. Relative paths are susceptible to errors.
Upvotes: 2
Reputation: 396
If you using virtual environment, when you install pyside6 with pip in the virtual environment there is a folder named Scripts there is the pyside6-uic.exe tool.
if you have install pyside6 globally in your system and you use visual studio code you can use the extension PySide2-vsc then when you installed you can go to preferences > settings and search the PySide2-vsc extension settings then look for the "Command to compile a .ui file into python". Then you can use that feature with right-click on .ui files.
Upvotes: 1