安装PyQ

2024-04-26 01:05:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图在我的mac上安装PyQt,以便安装python ghost。我已经安装了Qt和SIP。我已经下载了PyQt,但是当我运行

python configure-ng.py    

我得到以下错误:

Error: Use the --qmake argument to explicitly specify a working Qt qmake.

对我该怎么做有什么想法吗?


Tags: thepyuseconfiguremac错误errorargument
3条回答

没有使用PyCharm IDE的命令行。我也不需要安装Qt。:

  • 下载Python3.6.1(双击安装)。
  • 下载PyCharm IDE(双击安装)。
    • 转到PyCharm>;首选项>;项目解释程序。
    • 将项目解释器路径指向python.3.6.1
    • “+”按钮,搜索pyqt5。选择PyQt5版本5.8.2,然后单击“安装软件包”。

enter image description here

它将自动安装PyQt 5.8.2和SIP。刚安装完之后,请返回到项目解释器并确保SIP也已安装。如果未安装,“+”按钮并安装sip。

enter image description here

试试这个代码,看看它是否也适合你。:)

#!/usr/bin/env python3

from PyQt5.QtWidgets import QLabel, QVBoxLayout, QWidget
from PyQt5.QtCore import Qt


class Example(QWidget):

def __init__(self):
    super().__init__()
    self.initUI()

def initUI(self):
    self.setFixedSize(200, 100)
    self.setWindowTitle('Example')
    label = QLabel('Hello')
    layout = QVBoxLayout()
    layout.addWidget(label)
    layout.setAlignment(Qt.AlignCenter)
    self.setLayout(layout)


if __name__ == '__main__':

import sys
from PyQt5.QtWidgets import QApplication

app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())

enter image description here

既然你在Mac上,我就用Homebrew。前几天这对我很有效,但花了很长时间才完成:

brew install pyqt

configure-ng.py同时需要qmakesip来配置生成过程。

错误消息表示configure-ng.py找不到qmake可执行文件。您需要指定其位置,如下所示:

$ python configure-ng.py --qmake=/path/to/qmake

qmake的位置取决于1)如何安装它,2)正在使用的操作系统。


对于Mac操作系统,不那么痛苦的方法(在我的例子中)是使用自制程序安装sipqmake

$ brew install sip

$ brew install qt

brew will install them in the directory: /usr/local/Cellar/

然后,运行configure-ng.py并指定两个位置:

$ python configure-ng.py --qmake=/usr/local/Cellar/qt/VERSION/bin/qmake --sip=/usr/local/Cellar/sip/VERSION/bin/sip

如果一切正常,请继续PyQt安装:

$ make 

make需要一段时间(在我的情况下大约需要20分钟)。

最后,安装:

$ make install

make may needs admin permission $ sudo make

相关问题 更多 >