Qt5.7 with python2.7

6 篇文章 0 订阅

1. Problem

官方只提供qt5_py3.4,并没有py2.7的版本,需要自己编译生成。 需要先安装Qt5.7, 并把/usr/bin/qmake指向Qt5.7的qmake。

2. Code

#!/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 "###############################################################"

3. Test

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

4. Error list

1.TypeError: super() takes at least 1 argument (0 given)

super()

替换为

super(QObject, self)

QObject是当前定义的类的父类。

$. Reference

  1. http://www.cnblogs.com/kongkongyzt/p/3491406.html
  2. http://stackoverflow.com/questions/10838596/python-class-super-variable
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值