Python 2.7.13 を pyenv を使ってインストールしてある環境に wxPython をインストールして使用しようとしたメモを記録しておく。

wxPython は GUI アプリケーションを作るためのライブラリである。

https://wxpython.org

 

 

$pip search wxPython

...

wxPython (2.9.1.1)                              - Cross platform GUI toolkit for Python

...

 

と見つかったので、

 

$pip install wxPython

 

としたところ、

 

Collecting wxPython

  Could not find a version that satisfies the requirement wxPython (from versions: )

No matching distribution found for wxPython

 

とエラーがでてインストールできず。

調べたところ、

 

$pip install --user --pre --trusted-host wxpython.org -f http://wxpython.org/Phoenix/snapshot-builds/ wxpython-phoenix

 

でインストールできるとのことだった(参考にさせて頂いたHP)ので、実行したところインストール完了。

 

>>> import wx

>>> app=wx.App()

 

としたところ、import は無事できたが App() でエラー。

 

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.

 

調べたところ、pyenv のインストール時にオプションを渡すことで解決できるとあった(参考にさせて頂いたHP)ので、

 

$pytenv uninstall 2.7.13

$env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 2.7.13

 

を実行し、再度 wxPython をインストール

 

$pip install --user --pre --trusted-host wxpython.org -f http://wxpython.org/Phoenix/snapshot-builds/ wxpython-phoenix

 

この状態で

 

>>> import wx

>>> app=wx.App()

 

を実行したところ、エラーなく実行できた。

以下のテストコードで window を表示することができた。

 

>>> import wx

>>> app=wx.App()

>>> frame = wx.Frame(None, wx.ID_ANY, "Hello")

>>> frame.Show()

>>> app.MainLoop()

 

 


やじるし Python 関連メモの目次