Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wxPython and PyCharm on Mac

I'm trying to run Gooey which requires wxPython via PyCharm on my Mac (Sierra).

I have python and wxPython installed via homebrew and a virtual environment setup via the "Project Interpreter" preferences in PyCharm. Unfortunately, I'm getting the following error :

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.

I've seen various discussions of this issue around including : https://wiki.wxpython.org/wxPythonVirtualenvOnMac

Unfortunately, none of the solutions seems to work with my particular setup with PyCharm. Is there some way to specify a Framework build of python via PyCharm?

like image 201
agf1997 Avatar asked Mar 22 '26 00:03

agf1997


1 Answers

I've find a workaround for this issue.

  1. Check that you have wxPython installed, try to import wx from Python 3 interpreter.

    python3 -c 'import wx; print(wx.version())'

  2. That command returns 4.0.6 osx-cocoa (phoenix) wxWidgets 3.0.5 for me

  3. Start a new Python project in Pycharm, using venv and make sure you check the option Inherit global-site packages like this.
  4. Test.

Test example

import wx

if __name__ == '__main__':
    app = wx.App()
    window = wx.Frame(None, title="wxPython Frame", size=(300, 200))
    panel = wx.Panel(window)
    label = wx.StaticText(panel, label="Hello World", pos=(100, 50))
    window.Show(True)
    app.MainLoop()
like image 142
Carlos Avatar answered Mar 24 '26 13:03

Carlos