のんびりしているエンジニアの日記

ソフトウェアなどのエンジニア的な何かを書きます。

PyQtのインストール

Sponsored Links

皆さんこんにちは
お元気ですか?私は元気です。

さて、今日はPyQtのインストールです。
PyQtとは、QtをPythonで扱うためのライブラリです。

なぜか、結構手こずったので、残しておきます。
SIPとqtが必要です。

qt4(1) インストールについて - のんびりしているエンジニアの日記

install

SIP install

wget wget http://www.riverbankcomputing.com/static/Downloads/sip4/sip-4.16.2-snapshot-449e2866018a.tar.gz
tar zxvf sip-4.16.2-snapshot-449e2866018a.tar.gz
cd sip-4.16.2-snapshot-449e2866018a.tar.
python configure.py
make 
make all

これで完了です!

次にPyQt4のインストール

wget http://www.riverbankcomputing.com/static/Downloads/PyQt4/PyQt-mac-gpl-4.11.1-snapshot-e1e46b3cad30.tar.gz
tar zxvf PyQt-mac-gpl-4.11.1-snapshot-e1e46b3cad30.tar.gz
cd PyQt-mac-gpl-4.11.1-snapshot-e1e46b3cad30
python configure.py

実行していると途中で何か聞かれます。
内容はライセンスの確認と承認ですね。問題なければyesを打ちましょう

This is the GPL version of PyQt 4.11 (licensed under the GNU General Public
License) for Python 2.7.5 on darwin.

Type '2' to view the GPL v2 license.
Type '3' to view the GPL v3 license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.
 
Do you accept the terms of the license? yes
make install
make

もしここまででエラーが出たら、qt自体を入れなおしてみてください。コマンドは少し変更して以下のとおり

brew install qt --HEAD

起動実験

さて、インストール確認の為、簡単なプログラムを実行してみましょう。

#coding:utf-8
import PyQt4.QtCore as QtCore
import PyQt4.QtGui as QtGui
import sys

if __name__ == '__main__':
	application = QtGui.QApplication(sys.argv)

	panel = QtGui.QWidget()
	panel_layout = QtGui.QVBoxLayout()
	panel.setLayout(panel_layout)

	main_window =QtGui.QMainWindow()
	main_window.setCentralWidget(panel)
	main_window.show()

	application.exec_()