Unable to Launch Qt uic
Asked Answered
C

7

6

I have installed Qt designer 4.8.2, Pyside, and Python 3.3. When I create a form with Qt designer I am not able to see the code when clicking on view code. The error message is:"Unable to launch C:\Qt\4.8.2\bin\uic". I have the pyuic under C:\Python33\Lib\site-packages\PyQt4\uic. Please help.

Cadaverous answered 9/12, 2012 at 22:25 Comment(1)
It looks like that path is hard-wired into Qt Designer. I usually just setup a Makefile that calls uic, so you don't need to use Designer to view your generated code.Altonaltona
K
3

Although you can certainly use Qt Designer for creating UIs for PySide/PyQt, you should be aware that it is primarily a C++ tool - it doesn't have any built in support for Python. So the "View Code..." command you refer to only produces C++ code - which is probably not much use to you if you intend using PySide or PyQt.

Qt Designer UI files are in an XML format (they usually have a .ui extension).

To use them with Python, there are basically two options:

  1. Load the .ui files directly into your application.
  2. Convert the .ui files into Python modules using an external tool.

There are several differences between PySide and PyQt in how these two options are implemented.

For PyQt, the full documention for both options can be found here.

For PySide, the documentation for option 1 can be found here - but it does not look like there is any documentation for option 2. However, the external tool for PySide (which is called pyside-uic) works very similarly to the one for PyQt (which is called called pyuic4).

If you need more general information about how to get started using Qt with Python, try the PySide Wiki or the PyQt Wiki.

Kwangchow answered 10/12, 2012 at 3:11 Comment(2)
+1 for focusing on the distinction of Qt Designer being targeted for C++ projects. I used it solely for doing complicated layouts, or just visual brainstorming. Most of the features should be disregarded when doing a PyQt/PySide project. Just use it to do a layout and save a ui and/or resource file.Additive
Thank you! I was able to generate the py file from the ui file. However, when I run the generated python code I have the following errors. I seem to have a problem with the docstring?? Thanks much. text, filename = doctest._load_testfile(filename, None, False, "utf-8")File "C:\Python33\lib\doctest.py", line 223, in _load_testfile return f.read(), filename File "C:\Python33\lib\codecs.py", line 300, in decode(result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byteCadaverous
W
6

Just create a directory where it search for uic.exe file and copy existing uic.exe file to that directory.

My example : When I clicked View Code it shows Error asking for file uic.exe in path C:\python374\Lib\site-packages\pyqt5_tools\Qt\bin\bin

But I found uicexe file is in C:\python374\Lib\site-packages\pyqt5_tools\Qt\bin folder So I created another bin folder and copied uic.exe into that folder . That solved my problem.

Waly answered 25/8, 2019 at 7:48 Comment(0)
W
5

If you were looking to generate python code, you would do this from the console. So, if you saved your file from the program as 'untitled', the default, run this:

 pyuic5 -m untitled.ui -o untitled.py

Making sure your working directory is the file location of 'untitled.ui'. It will then spit untitled.py into the same place.

Wile answered 13/10, 2018 at 22:34 Comment(0)
B
4

Create a folder called bin inside the folder and move the exe inside uic.exe. It shows the code when click the view code from the QT designer.

enter image description here

Behalf answered 21/10, 2020 at 14:13 Comment(0)
K
3

Although you can certainly use Qt Designer for creating UIs for PySide/PyQt, you should be aware that it is primarily a C++ tool - it doesn't have any built in support for Python. So the "View Code..." command you refer to only produces C++ code - which is probably not much use to you if you intend using PySide or PyQt.

Qt Designer UI files are in an XML format (they usually have a .ui extension).

To use them with Python, there are basically two options:

  1. Load the .ui files directly into your application.
  2. Convert the .ui files into Python modules using an external tool.

There are several differences between PySide and PyQt in how these two options are implemented.

For PyQt, the full documention for both options can be found here.

For PySide, the documentation for option 1 can be found here - but it does not look like there is any documentation for option 2. However, the external tool for PySide (which is called pyside-uic) works very similarly to the one for PyQt (which is called called pyuic4).

If you need more general information about how to get started using Qt with Python, try the PySide Wiki or the PyQt Wiki.

Kwangchow answered 10/12, 2012 at 3:11 Comment(2)
+1 for focusing on the distinction of Qt Designer being targeted for C++ projects. I used it solely for doing complicated layouts, or just visual brainstorming. Most of the features should be disregarded when doing a PyQt/PySide project. Just use it to do a layout and save a ui and/or resource file.Additive
Thank you! I was able to generate the py file from the ui file. However, when I run the generated python code I have the following errors. I seem to have a problem with the docstring?? Thanks much. text, filename = doctest._load_testfile(filename, None, False, "utf-8")File "C:\Python33\lib\doctest.py", line 223, in _load_testfile return f.read(), filename File "C:\Python33\lib\codecs.py", line 300, in decode(result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byteCadaverous
F
1

To make

Form -> View code

work, directly from Qt Designer using either Qt4 or Qt5, you can just create a symbolic link from where Qt Designer is looking, pointing to where your pyuic5.exe executable is. With your example, it would be:

mklink /H "C:\Qt\4.8.2\bin\uic.exe" "C:\Python33\Lib\site-packages\PyQt4\pyuic4.exe"

Which is:

mklink /H "Path\to\uic.exe\file\Qt\designer\is\looking\for" "Path\to\actual\location\of\pyuic4.exe\or\pyuic5.exe\file"

Make sure the folder where "C:\Qt\4.8.2\bin\uic.exe" will reside exists obviously.

Flyn answered 6/2, 2019 at 11:8 Comment(0)
S
0

For Linux computers

If anyone still stuck with this problem and you are using Linux.

You can find the required uic file in venv-path/python3.x/site-packages/PySide2/uic Copy this file, and create a new folder bin inside the Qt folder.venv-path/python3.x/site-packages/PySide2/Qt/bin

now place the uic file there, such that, the final uic path is: venv-path/python3.x/site-packages/PySide2/Qt/bin/uic

Note::

  • venv-path is the path to you python virtual-environment.
  • 3.x is the appropriate version of the Python in the virtual-environment. (In my case it's 3.8)

Final Result:

enter image description here

Sharpie answered 11/7, 2021 at 17:5 Comment(0)
E
0
python -c "import os; import PySide6; src = PySide6.__path__[0]; dst = src + '/bin'; os.mkdir(dst) if not os.path.exists(dst) else None; os.symlink(src + '/uic.exe', dst + '/uic.exe')"

I had the same error\warning message on Windows with pyside6-designer, I just run the above line as administrator and everything now works as expected (The line, simply creates a link of the uic.exe inside a bin-folder under the Pyside6 module's folder).

Etruria answered 1/5, 2022 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.