简体   繁体   中英

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?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM