MAC LINUX 安装PYQT(事例)

MAC安装

1、安装命令:brew install pyqt

Warning: Your Xcode (4.6.3) is outdated
Please install Xcode 5.0.
Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Installing dependencies for pyqt: qt, sip
==> Installing pyqt dependency: qt
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/qt-4.8.5.mountain_lion.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring qt-4.8.5.mountain_lion.bottle.2.tar.gz
==> Caveats
We agreed to the Qt opensource license for you.
If this is unacceptable you should uninstall.
==> Summary
?  /usr/local/Cellar/qt/4.8.5: 2777 files, 119M
==> Installing pyqt dependency: sip
==> Downloading http://download.sf.net/project/pyqt/sip/sip-4.15.2/sip-4.15.2.tar.gz
######################################################################## 100.0%
==> /usr/bin/python configure.py --destdir=/usr/local/Cellar/sip/4.15.2/lib/python2.7/site-packages --bindir=/usr/local/Cellar/sip/4.15.2/bin --incdir=/usr/local/Cellar/sip/4.15.2/i
==> make
==> make install
==> make clean
==> Caveats
For non-homebrew python (2.x), you need to amend your PYTHONPATH like so:
  export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
The sip-dir for Python 2.x is /usr/local/share/sip.
The sip-dir for Python 3.x is /usr/local/share/sip3.
==> Summary
?  /usr/local/Cellar/sip/4.15.2: 9 files, 632K, built in 11 seconds
==> Installing pyqt
==> Downloading http://downloads.sf.net/project/pyqt/PyQt4/PyQt-4.10.3/PyQt-mac-gpl-4.10.3.tar.gz
######################################################################## 100.0%
==> /usr/bin/python configure.py --confirm-license --bindir=/usr/local/Cellar/pyqt/4.10.3/bin --destdir=/usr/local/Cellar/pyqt/4.10.3/lib/python2.7/site-packages --sipdir=/usr/local
==> /usr/bin/python ./configure-ng.py --confirm-license --bindir=/usr/local/Cellar/pyqt/4.10.3/bin --destdir=/usr/local/Cellar/pyqt/4.10.3/lib/python2.7/site-packages --sipdir=/usr/
==> make
==> make install
==> make clean
==> Caveats
For non-homebrew python (2.x), you need to amend your PYTHONPATH like so:
  export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
==> Summary
?  /usr/local/Cellar/pyqt/4.10.3: 560 files, 18M, built in 8.5 minutes

 2、添加路径到

  • 在~/.bash_profile 添加如下一行
    export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
  • 然后 source ~/.bash_profile

3、添加测试程序 w1.py

import sys
import time
from PyQt4 import QtGui, QtCore, QtWebKit

class Sp():
    def save(self):
        print "call"
        data = self.webView.page().currentFrame().documentElement().toInnerXml()
        open("htm.txt","w").write(data)
        print 'finished'
        time.sleep(5)
        print 'finisheed......2'
         #sys.exit()
        
    def txtfile(self):
        print "starting..."    

    def main(self):
        self.webView = QtWebKit.QWebView()      
        self.webView.load(QtCore.QUrl("http://www.taobao.com"))
        self.webView.show()
        QtCore.QObject.connect(self.webView,QtCore.SIGNAL("loadFinished(bool)"),self.save)

app = QtGui.QApplication(sys.argv)
s = Sp()
#s.txtfile()
s.main()

sys.exit(app.exec_())
#sys.exit()

4、执行程序

  • python w1.py
@~/Downloads $ python w1.py 
call
finished
finisheed......2
call
finished
finisheed......2
call
finished
finisheed......2
Traceback (most recent call last):
  File "w1.py", line 6, in save
    def save(self):
KeyboardInterrupt

linux

我使用的是刚刚安装的UBUNTU

1 安装杂七杂八的软件

1.1 sudo apt-get install build-essential

1.2 我的的Python是2.6.5,所以我安装的命令是:sudo apt-get install python2.6-dev

1.3 sudo apt-get install flex

2 安装sip

  • 下载:http://www.riverbankcomputing.co.uk/software/sip/download/
  • 解压:tar -zxvf sip-4.15.4-snapshot-7a74623b6967.tar.gz
  • 安装:python configure.py
  • make
  • sudo make install

3 安装QT相关 sudo apt-get install libxext6 libxext-dev libqt4-dev libqt4-gui libqt4-sql qt4-dev-tools qt4-doc qt4-designer qt4-qtconfig

4 安装PYQT

  • 下载:http://www.riverbankcomputing.co.uk/software/pyqt/download
  • 解压:tar 省略
  • 编译:make (差不多半个小时)
  • sudo make install

成功啦! 

转载于:https://www.cnblogs.com/liqiu/p/3361948.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值