简体   繁体   English

为什么我在 macOS Catalina 下收到错误:Cannot run 'uic': “execvp: No such file or directory” for a PySide2 program?

[英]Why do I get the error: Cannot run 'uic': “execvp: No such file or directory” for a PySide2 program under macOS Catalina?

I want to execute a program which was written in python using PyQt5 and then migrated to PySide2 under MacOS Catalina.我想执行一个使用 PyQt5 用 python 编写的程序,然后在 MacOS Catalina 下迁移到 PySide2。 With PyQt5 it was executing fine.使用 PyQt5,它运行良好。 I have installed PySide2 like PyQt5:我已经像 PyQt5 一样安装了 PySide2:

python3 -m pip install PyQt5
python3 -m pip install PySide2

macOS was restarted afterwards.之后重新启动了 macOS。

Now, with PySide2 installed, I am getting an error in macOS when I am trying to load an Ui-file.现在,安装 PySide2 后,当我尝试加载 Ui 文件时,在 macOS 中出现错误。

MRE which works under Linux, Windows and macOS Catalina: MRE 适用于 Linux、Windows 和 macOS Catalina:

#!/usr/bin/env python3

# Standard library imports
import sys

# Third party imports
from PySide2.QtCore import (QMetaObject,
                            Slot)
from PySide2.QtWidgets import (QApplication,
                               QWidget,                               
                               QPushButton,
                               QHBoxLayout,
                               QMessageBox)

def show_about():
    msg = QMessageBox()

    msg.setText("About this app.")
    msg.setStandardButtons(QMessageBox.Ok)

    msg.exec_()
    
class MainWindow(QWidget):    
    def __init__(self):        
        super().__init__()
        self.initUI()
        
    def initUI(self):        
        aboutButton = QPushButton("About")
        aboutButton.setObjectName("aboutButton")
        
        hbox = QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(aboutButton)        
        
        self.setLayout(hbox)
        
        QMetaObject.connectSlotsByName(self)
                
        self.setWindowTitle('Buttons')        
            
    @Slot()
    def on_aboutButton_clicked(self):
        show_about()
        
def main():    
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

MRE which fails under macOS Catalina, but works in Linux and Windows: MRE 在 macOS Catalina 下失败,但在 Linux 和 Windows 中有效:

#!/usr/bin/env python3

# Standard library imports
import sys

# Third party imports
from PySide2.QtWidgets import (QApplication,
                               QMainWindow)

from PySide2.QtUiTools import loadUiType
   
class MainWindow(QMainWindow, loadUiType("win_main.ui")[0]):    
    def __init__(self):        
        super().__init__()
        self.setupUi(self)


def main():
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

Error:错误:

Python 3.8.5 (/usr/local/bin/python3)
>>> %Run pyside2_win_main.py
Cannot run 'uic':  "execvp: No such file or directory"  -  Exit status  QProcess::NormalExit  ( 255 )
 Check if 'uic' is in PATH
Traceback (most recent call last):
  File "/Users/dee/ownCloud3/rma2/pyside2_win_main.py", line 12, in <module>
    class MainWindow(QMainWindow, loadUiType("win_main.ui")[0]):
TypeError: 'NoneType' object is not subscriptable

File structure for simplicity of test case:为简化测试用例的文件结构:

/Users/dee/ownCloud3/rma2/pyside2_win_main.py
/Users/dee/ownCloud3/rma2/win_main.ui

PySide2 version 15.5.0, shiboken2==5.15.0. PySide2 版本 15.5.0,shiboken2==5.15.0。

macOS Calatina v10.15.06 macOS Calatina v10.15.06

Python 3.8.5 64bit (downloaded from here , no HomeBrew etc. Python 3.8.5 64bit(从这里下载,没有 HomeBrew 等。

Don't use relative paths as they are susceptible to errors as it will depend on how the script is run, instead build an absolute path:不要使用相对路径,因为它们容易出错,因为这取决于脚本的运行方式,而是构建绝对路径:

import os.path


CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
ui_file_path = os.path.join(CURRENT_DIR, "win_main.ui")


Ui_Class, _ = loadUiType(ui_file_path)


class MainWindow(QMainWindow, Ui_Class):
    # ...

Also add at the top of your file, since it seems that when python was installed, the option to add the necessary paths to the environment variables was not marked:还要在文件顶部添加,因为似乎在安装python时,未标记将必要路径添加到环境变量的选项:

import PySide2 
import os.path  

uic_dir = os.path.dirname(PySide2.__file__) 
os.environ["PATH"] += os.pathsep + uic_dir

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在 macOS 上收到“没有这样的文件或目录”错误? - Why do I get a "No such file or directory" error on macOS? 如何解决错误“找不到名为 pyside2 的模块”? - How do I solve error "no module found named pyside2"? 为什么我在 windows PC 上尝试安装 PySide2 时总是出错? - Why do I keep getting errors when I try to install PySide2 on windows PC? 为什么我在运行此程序时会收到 Terminator 错误? - Why do I get a Terminator error when I run this program? 为什么我的PySide2中的QVideoFilterRunnable的“ run()”方法没有执行? - Why is the “run()” method of my QVideoFilterRunnable in PySide2 not being executed? 使用 PySide2 和 QTableView 我如何使用 pandas model 在表视图中获得多个代表? - With PySide2 and QTableView how do i get multiple delegates in table view using pandas model? 无法运行程序“ pip --version”(在目录“。”中):error = 2,没有这样的文件或目录 - Cannot run program “pip --version” (in directory “.”): error=2, No such file or directory 没有黑客就无法在PySide2上使用QAbstractListModel子类 - Cannot get a QAbstractListModel subclass working on PySide2 without a hack 我可以将 PySide2 应用程序作为 Windows 后台进程运行吗 - Can I run an PySide2 application as a Windows Background Process 带有 PySide2 的文件浏览器:获取文件的路径,然后杀死 GUI - File Browser with PySide2: get the path of the file and then kill the GUI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM