LoginSignup
13

More than 5 years have passed since last update.

MacでPySide + PyInstaller -> 空のqt.confを置く

Last updated at Posted at 2014-11-04

MacでPySideを使ったPythonプログラムをexe化する時にはまったのでメモ。
Pythonは膨大なライブラリを駆使するスクリプト言語なので、コーディングが爆速になるメリットの一方で、他人にプログラムを渡す時には自分が書いたスクリプト(群)+Pythonインタプリタ本体+依存するライブラリをまとめて一つの実行形式(要はexe)にするという作業(freezeと言ったりする)が必須になります。

Pythonスクリプトをexe化するツール自体は世の中にいろいろあり、PyInstallerは中でも一番シンプルで、githubからV2.1のtagあたりを拝借して、以下のように呼び出せばdist/hoge(.exe)が一瞬でできたりします。

python pyinstaller/pyinstaller.py --onefile hoge.py

Qtを使うとはまる

さて、QtのPythonバインディングであるPyQtPySideを使ったスクリプト(群)をexe化する場合はだいたい一発では起動しません。今回Mac10.9でPySideを使ったスクリプトのexe化を試みたところ、pyinstaller.pyによるexe化自体は一発で通ったのですが、いざ実行しようとすると以下のようなエラーが笑えるほど出て、あっさり落ちる状態でした。要はMacにもともと入っているQtとどっちを読めばいいか分からなくなって困っているようです。

objc[20102]: Class QCocoaWindow is implemented in both /var/folders/qk/z4x58g2962q21q5570g2hj0c0000gn/T/_MEIftohUI/QtGui and /Library/Frameworks/QtGui.framework/Versions/4/QtGui. One of the two will be used. Which one is undefined.

On Mac OS X, you might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.

touch dist/qt.conf

で、いろいろ情報を漁って最終的にたどり着いた回避方法がqt.confという空のファイルをexeの横に置くというただそれだけ。こちらにあった情報なのですが、遭遇率が高い問題の割にはここ以外で見つけられませんでした。同じことではまることになる方のために記録です。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13