官方只提供qt5_py3.4,并没有py2.7的版本,需要自己编译生成。 需要先安装Qt5.7, 并把/usr/bin/qmake指向Qt5.7的qmake。
#!/usr/bin/env bash
SIP_VERSION=4.19
QT_VERSION=5.7.1
echo "###############################################################"
echo "Start the installation of sip,which is an import tool to call "
echo "gcc compile source code of pyqt into binary code"
echo "###############################################################"
cd ~/Downloads
wget http://sourceforge.net/projects/pyqt/files/sip/sip-${SIP_VERSION}/sip-${SIP_VERSION}.tar.gz
tar -xzf sip-${SIP_VERSION}.tar.gz
cd sip-${SIP_VERSION}
python configure.py --platform linux-g++ && \
make && \
sudo make install
echo "###############################################################"
echo "Start the installation of pyqt "
echo "It will take some time because we need to compile the souece code"
echo "###############################################################"
wget http://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-${QT_VERSION}/PyQt5_gpl-${QT_VERSION}.tar.gz
tar -xzf PyQt5_gpl-${QT_VERSION}.tar.gz
cd PyQt5_gpl-${QT_VERSION}
python configure.py && \
make && \
sudo make install
echo "###############################################################"
echo "All the installation has done! please check your installation"
echo "###############################################################"
test.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt5.QtNetwork import *
from PyQt5.QtQml import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class MainWin(object):
def __init__(self):
self.eng = QQmlApplicationEngine()
self.eng.load('main.qml')
win = self.eng.rootObjects()[0]
win.show()
if __name__ == '__main__':
import sys
App = QApplication(sys.argv)
Win = MainWin()
sys.exit(App.exec_())
main.qml
import QtQuick 2.2
import QtQuick.Controls 1.0
ApplicationWindow {
id: main
width: 400
height: 600
color: 'grey'
}
运行
python test.py
1.TypeError: super() takes at least 1 argument (0 given)
把
super()
替换为
super(QObject, self)
QObject是当前定义的类的父类。