Skip to content

Python3系統でwxPythonを使う

PythonでGUIアプリを作ろうと思ってwxPythonを使おうと思ったけどめちゃくちゃ苦労した.

いろいろなページでwxPythonのインストールの仕方が書いてあるが
homebrewを使う方法だと古い?バージョンのwxPythonがインストールされてしまいうまくいかなかった.

そこでpip3を使ってインストール
参考ページをコピペして実行

% pip3 install http://www.wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1830+0b5f910-cp34-cp34m-macosx_10_6_intel.whl


wxPython_Phoenix-3.0.3.dev2700+c524ed1-cp34-cp34m-macosx_10_6_intel.whl
is not a supported wheel on this platform.

wheelが入ってないからエラー?
とりあえずwheelをインストール

% pip3 install wheel

もう一回先ほどのコードを実行...
またエラー

どうやら参照しているwxPythonのバージョンが違うみたい
cp34はPython3.4系列. cp27だとPython2.7系列みたいな感じ
自分のバージョンにあったものをこちらのサイトから取ってきてください.

自分はPython3.5.3を入れていたのでcp35バージョンで再挑戦

pip3 install https://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev2700+c524ed1-cp35-cp35m-macosx_10_6_intel.whl
Collecting wxPython-Phoenix==3.0.3.dev2700+c524ed1 from https://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev2700+c524ed1-cp35-cp35m-macosx_10_6_intel.whl
  Downloading https://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev2700+c524ed1-cp35-cp35m-macosx_10_6_intel.whl (33.9MB)
    100% |████████████████████████████████| 33.9MB 40kB/s 
Collecting six (from wxPython-Phoenix==3.0.3.dev2700+c524ed1)
  Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, wxPython-Phoenix
Successfully installed six-1.10.0 wxPython-Phoenix-3.0.3.dev2700+c524ed1

なんとか成功. とりあえずimportしてみる

% python3
>>> import wx
>>> exit

次にサンプルコードを実行

%python3 window.py
<span style="color: red;">
This program needs access to the screen. Please run with a
Framework build of python, and only when you are logged in
on the main display of your Mac.</span>

なんか怒られた...そこでpython3ではなくpythonwでコンパイルする.

% pythonw window.py

エラー出ずに成功...Pythonのインストール含め,6時間は格闘した笑

import wx

application = wx.App()

frame = wx.Frame(None,wx.ID_ANY, u"TestWindow")
frame.Show()

application.MainLoop()

参考ページ
脱初心者を目指す-python3用のwxPythonをインストールする
myView2 (クライアントPC用LHDデータ表示プログラム)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です