seanwu1105 / vscode-qt-for-python

Qt for Python (PySide and PyQt) extension for Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=seanwu.vscode-qt-for-python
MIT License
186 stars 15 forks source link

In VSCode, an error is reported by right-clicking to compile the ui file #301

Closed YunchengLiu closed 1 year ago

YunchengLiu commented 1 year ago

I installed Pyside6 in a new conda environment via conda install pyside6, and i config this plugin as follows.

  "qtForPython.rcc.path": "C:/Miniconda3/envs/qt/Scripts/pyside6-rcc.exe",
  "qtForPython.uic.path": "C:/Miniconda3/envs/qt/Scripts/pyside6-uic.exe",
  "qtForPython.designer.path": "C:/Miniconda3/envs/qt/Library/bin/designer.exe",
  "qtForPython.rcc.liveExecution": false,
  "qtForPython.uic.liveExecution": false,
  "qtForPython.uic.options": [
      "-o \"${workspaceFolder}${pathSeparator}qt_out${pathSeparator}ui_${fileBasenameNoExtension}.py\""
  ]

I created a new ui file, which can be opened through the designer, but when I right-click and select Compile Qt UI File in the VSCode file browser, the output is (Sorry for some garbled characters, I don't know why):


**Traceback (most recent call last): File "C:\Miniconda3\envs\qt\Scripts\pyside6-uic-script.py", line 10, in sys.exit(uic()) ^^^^^ File "C:\Miniconda3\envs\qt\Lib\site-packages\PySide6\scripts\pyside_tool.py", line 83, in uic qt_tool_wrapper("uic", ['-g', 'python'] + sys.argv[1:], True) File "C:\Miniconda3\envs\qt\Lib\site-packages\PySide6\scripts\pyside_tool.py", line 49, in qt_tool_wrapper proc = Popen(cmd, stderr=PIPE) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Miniconda3\envs\qt\Lib\subprocess.py", line 1024, in init self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Miniconda3\envs\qt\Lib\subprocess.py", line 1509, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [WinError 2] ϵͳ�Ҳ���ָ�����ļ���

Command failed: C:/Miniconda3/envs/qt/Scripts/pyside6-uic.exe -o "d:_Code\MetaHoloPolar\qt_out\ui_untitled.py" d:_Code\MetaHoloPolar\untitled.ui Traceback (most recent call last): File "C:\Miniconda3\envs\qt\Scripts\pyside6-uic-script.py", line 10, in sys.exit(uic()) ^^^^^ File "C:\Miniconda3\envs\qt\Lib\site-packages\PySide6\scripts\pyside_tool.py", line 83, in uic qt_tool_wrapper("uic", ['-g', 'python'] + sys.argv[1:], True) File "C:\Miniconda3\envs\qt\Lib\site-packages\PySide6\scripts\pyside_tool.py", line 49, in qt_tool_wrapper proc = Popen(cmd, stderr=PIPE) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Miniconda3\envs\qt\Lib\subprocess.py", line 1024, in init self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Miniconda3\envs\qt\Lib\subprocess.py", line 1509, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [WinError 2] ϵͳ�Ҳ���ָ�����ļ���**


I am in the python environment, manually using python pyside6-uic-script.py file.ui > ui_file.py can compile successfully.

I want to know how to solve this problem, thanks a lot

pizza-yute commented 1 year ago

I was facing the same problem, turns out, it's easy to solve

  1. First, go into the extension settings in VS Code.

  2. Locate the setting "Qt For Python › Uic: Path", for me it was the last setting.

  3. Put the path of the uic.exe executable in it, NOT the pyside6-uic.exe, in the issue I saw you put C:/Miniconda3/envs/qt/Scripts/pyside6-uic.exe, whereas it should have been C:/Miniconda3/envs/qt/Lib/site-packages/PySide6/bin/uic.exe If the folder bin does not exist in that directory, just create the bin folder and move the uic.exe file inside of it. (the uic.exe file should be in C:/Miniconda3/envs/qt/Lib/site-packages/PySide6/uic.exe)

  4. Once all of this is done, you can close VS Code and restart it, and you should be able to compile the .ui file.

NOTE If you want to compile it into Python code and not C++, you have to do 1 more step.

  1. Go to the extension settings in VS Code and look for the setting Qt For Python › Uic: Options, for me it was right above the previous one.

  2. And add the next line -g python .

  3. That should be it.

YunchengLiu commented 1 year ago

Thanks! i solved it!

pizza-yute commented 1 year ago

Glad its sorted!