Installing PyQt

那年仲夏 提交于 2019-12-03 12:23:53

问题


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

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?


回答1:


Since you are on a Mac, I would use Homebrew. This worked for me the other day, but took a long time to finish:

brew install pyqt



回答2:


configure-ng.py needs both qmake and sip to configure the build process.

The error message means that configure-ng.py could not locate the qmake executable. You need to specify its location, with something like this:

$ 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.


For Mac OS, the less painful way (in my case) is to install sip and qmake using Homebrew

$ brew install sip

$ brew install qt

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

Then, run configure-ng.py with specifying both locations:

$ 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:

$ make 

make takes a while (around 20 mins in my case).

And finally, install:

$ make install

make may needs admin permission $ sudo make




回答3:


Without command line using PyCharm IDE. Also I didn't need to install 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.

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.

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_())



来源:https://stackoverflow.com/questions/22678954/installing-pyqt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!