Search code examples
pythonwxpythonwxwidgets

wxPython: This program needs access to the screen


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!


Solution

  • This resolves the problem, but it can't be the prettiest solution:

    # install anaconda
    install anaconda
    
    # uninstall all versions of pythonWx
    pip uninstall pythonWx -y
    conda remove pythonwx
    
    # install the python.app binary through conda
    conda install python.app
    
    # determine where the conda binary lives
    which conda
    
    # that previous command returns something like: 
    # /Users/yaledhlab/anaconda3/bin/conda
    # replace the /conda with /python.app
    # and run the result in a terminal
    /Users/yaledhlab/anaconda3/bin/python.app
    
    # that should open a Python terminal (you know you're in the Python
    # terminal if you see >>> as a prefix for your shell)
    # import the python package manager and install wxPython to
    # your python.app version of Python
    import pip
    pip.main(['install', 'wxPython'])
    
    # exit the python interpreter
    exit()
    
    # run the program
    /Users/yaledhlab/anaconda3/bin/python.app main.py