Python 安装 PyQt
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22678954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing PyQt
提问by steeling
I'm trying to install PyQt on my mac so that I can install python ghost. I've already installed Qt, and SIP. I've downloaded PyQt, but when I run
我正在尝试在我的 mac 上安装 PyQt,以便我可以安装 python ghost。我已经安装了 Qt 和 SIP。我已经下载了 PyQt,但是当我运行时
python configure-ng.py
I get the following error:
我收到以下错误:
Error: Use the --qmake argument to explicitly specify a working Qt qmake.
Any ideas on what I should do?
关于我应该做什么的任何想法?
采纳答案by Manuel Riel
回答by Aziz Alto
configure-ng.pyneeds both qmakeand sipto configure the build process.
configure-ng.py需要qmake和sip来配置构建过程。
The error message means that configure-ng.pycould not locate the qmakeexecutable. You need to specify its location, with something like this:
错误消息意味着configure-ng.py无法找到qmake可执行文件。您需要指定它的位置,如下所示:
$ python configure-ng.py --qmake=/path/to/qmake
$ python configure-ng.py --qmake=/path/to/qmake
The location of qmake depends on 1) how you installed it and 2) the OS you are using.
qmake 的位置取决于 1) 您如何安装它以及 2) 您使用的操作系统。
For Mac OS, the less painful way (in my case) is to install sipand qmakeusing Homebrew
对于 Mac OS,不太痛苦的方法(就我而言)是安装sip和qmake使用 Homebrew
$ brew install sip
$ brew install sip
$ brew install qt
$ brew install qt
brewwill install them in the directory:/usr/local/Cellar/
brew将它们安装在目录中:/usr/local/Cellar/
Then, run configure-ng.pywith specifying both locations:
然后,在configure-ng.py指定两个位置的情况下运行:
$ python configure-ng.py --qmake=/usr/local/Cellar/qt/VERSION/bin/qmake --sip=/usr/local/Cellar/sip/VERSION/bin/sip
If all good, continue PyQt installation:
如果一切顺利,继续 PyQt 安装:
$ make
maketakes a while (around 20 mins in my case).
make需要一段时间(在我的情况下大约 20 分钟)。
And finally, install:
最后,安装:
$ make install
makemay needs admin permission$ sudo make
make可能需要管理员权限$ sudo make
回答by Jeremias Serafim
Without command line using PyCharm IDE. Also I didn't need to install Qt.:
没有使用 PyCharm IDE 的命令行。我也不需要安装 Qt。:
- Download Python 3.6.1 (double click to install).
- Download PyCharm IDE (double click to install).
- Go to PyCharm>Preferences>Project Interpreter.
- Point the project interpreter path to python.3.6.1
- '+' button, search for pyqt5. Choose PyQt5 version 5.8.2 than click install package.
- 下载 Python 3.6.1(双击安装)。
- 下载 PyCharm IDE(双击安装)。
- 转到 PyCharm>首选项>项目解释器。
- 将项目解释器路径指向 python.3.6.1
- '+' 按钮,搜索 pyqt5。选择 PyQt5 版本 5.8.2 然后点击安装包。
Automatically it is going to install PyQt 5.8.2 and SIP. After installed just, come back to Project Interpreter and make sure that SIP was installed too. If it is not installed: '+' button and install sip.
它会自动安装 PyQt 5.8.2 和 SIP。刚刚安装后,回到 Project Interpreter 并确保也安装了 SIP。如果未安装:“+”按钮并安装 sip。
Try this code to see if it works for you too. :)
试试这个代码,看看它是否也适合你。:)
#!/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_())


