wxPython: This program needs access to the screen

duhaime picture duhaime · Jan 30, 2018 · Viewed 7.9k times · Source

I'm trying to use the Python GUI wx (installable via pip install wxPython) in the following minimal app:

import wx
app = wx.App()

Running this snippet returns the following:

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.

Does anyone know how to help wx gain "access to the screen", or what a "Framework build of Python" is? I'd be grateful for any help others can offer with these questions!

Answer

ChameleonCoder picture ChameleonCoder · Oct 10, 2018

wxPython on Mac within a virtual environment throws this error, as explained by wxPython website here: https://wiki.wxpython.org/wxPythonVirtualenvOnMac

If you are not running it in a virtual environment and still receive this error, try running your script that uses wxpython with "pythonw" instead of "python". Ex:

pythonw hello.py

^See section "4.1.2 Running Scripts with a GUI" (on MacOS) from the following page in the Python Docs to see this python quirk explained: https://docs.python.org/3/using/mac.html