windows用のPyQt4をビルド

折角python2.7にしたのにnokiaさんRiverbankさんがPyQt4のpython2.7版をupしてくれないので自前でビルドしました。やり方を忘れないようにメモ。

基本的に上記サイトに書いてあることをそのままやっただけですが、微妙にパスが変わってた。

手順

qt-sdk-win-opensource-2010.04.exeでQt4のSDKをインストール(C:\Qt\2010.04)

設定はそのままでポチポチ押していく。一緒にmingwもインストールされる。

コマンドプロンプト(cmd.exe)を開く(cygwinやmsysはダメらしい)
環境変数PATHを設定
set PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Qt\2010.04\qt\bin;C:\Qt\2010.04\mingw\bin;C:\Python27
g++とqmakeにパスが通ったか確認
> g++ -v
Using built-in specs.
Target: mingw32
Configured with: ../gcc-4.4.0/configure --enable-languages=c,ada,c++,fortran,java,objc,obj-c++ --disable-sjlj-exceptions --enable-shared --enable-libgcj --enable-libgomp --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --prefix=/mingw --with-gmp=/mingw/src/gmp/root --with-mpfr=/mingw/src/mpfr/root --build=mingw32
Thread model: win32
gcc version 4.4.0 (GCC) 
> qmake -v
QMake version 2.01a
Using Qt version 4.6.3 in C:/Qt/2010.04/qt/lib
nmakeが必要なのでVisualStudioへパスを通す
> "%VS80COMNTOOLS%\vsvars32.bat"
sipをビルドしてインストール(ここだけ別にやり方でやったので動作未確認)
> cd sip-snapshot-20070704
> python configure.py -p win32-g++
> mingw32-make
> mingw32-make install
PyQt4をビルドしてインストール
> cd PyQt-win-gpl-4.7.3
> python configure.py -w
... 省略 ...
Do you accept the terms of the license? yes       ←ここで聞かれるので yes と入力
... 省略 ...
> mingw32-make
> mingw32-make install
環境変数PATHをQt4/MinGWに通さなくても良いようにQt4/MinGWのdllをPyQt4のディレクトリへコピー
> xcopy /D /Y /I /F C:\Qt\2010.04\qt\bin\*.dll C:\Python27\Lib\site-packages\PyQt4\
動作チェック
>>> from PyQt4.Qt import *
>>> from PyQt4.QtGui import *     # dllへのPATHが通ってないと読み込めない
>>> from sip import *
>>> print SIP_VERSION_STR, QT_VERSION_STR, PYQT_VERSION_STR
4.10.2 4.6.3 4.7.3

最後に

  • 64bit版をビルドする場合はQt4からビルドし直せばよいのかな?たぶん。あ、でもmingw32だとダメなのか?
  • QLibraryInfo.location()とかがC:\Qt\2010.04\qt\...を指してる。このままだとQt4のSDK消せない。どうしても直したければC:\Python27\Lib\site-packages\PyQt4\pyqtconfig.pyを弄れば変えられるのかも?
    • 変わんなかった。たぶんconfigure.pyのときの設定が出ているだけ?

追記 2010.07.09

  • python2.6にインストールしてあるPyQt4を見てみると、
    • pyqtconfig.pyのパスは下記の4点がPyQt4内になっている。
    'pyqt_bin_dir':      'C:\\Python26\\Lib\\site-packages\\PyQt4\\bin',
    'pyqt_config_args':  '-b C:\\Python26\\Lib\\site-packages\\PyQt4\\bin',
    'pyqt_mod_dir':      'C:\\Python26\\Lib\\site-packages\\PyQt4',
    'pyqt_sip_dir':      'C:\\Python26\\Lib\\site-packages\\PyQt4\\sip\\PyQt4',
    • というかpyqt_bin_dirってあるからそこにdllをコピーすべきっぽい?
    • sipのパスも微妙に違う

2010.07.12 追記