2

I want to install python from python.org and have it work with wxPython in a terminal on macOS:

  • Install python 3.9.13 using the macOS 64-bit universal2 installer
  • Install wxPython using pip - pip3 install -U wxPython
  • Start python in a shell and try and fire up a wx app:
DB0837:~ andypiper$ /Library/Frameworks/Python.framework/Versions/3.9/bin/python3
Python 3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:37:23) 
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.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.

Please don't point me at brew or pyenv or anaconda or framework builds - I want the above combination to work, and it seems not to. The download from python.org is a framework build and if I run this from IDLE it works fine using the exact same version of python, so it feels like it must be some macOS security issue or shell/python interaction

Andy Piper
  • 563
  • 4
  • 10
  • does this help: [wxpython-this-program-needs-access-to-the-screen](https://stackoverflow.com/questions/48531006/wxpython-this-program-needs-access-to-the-screen) – topsail Jul 09 '22 at 21:19
  • Literally no - that is the post I used to produce the demo program that doesn't work. Also note that pythonw no longer exists in python 3.9.x (not needed apparently) and the rest of the solutions involve anaconda - which I don't want. I want to get to the bottom of this specific scenario, not change it for a new scenario – Andy Piper Jul 10 '22 at 08:25
  • How about this: https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433 – topsail Jul 10 '22 at 15:40
  • I think this is just saying "use a framework build" - which I am – Andy Piper Jul 10 '22 at 18:48

1 Answers1

5

I had this problem on an existing codebase after upgrading to Monterey.

My app still worked when built with py2app, but not when running from the command line.

It seems like the underlying wxWidgets method IsDisplayAvailable started to fail, so I just removed the check.

It's in your site packages at wx/core.py, line 2183.

Change

   if not self.IsDisplayAvailable():

to

   if False:

and you are off to the races.

What can I say? It's very dirty, but I'm working again.

Gareth Simpson
  • 36,943
  • 12
  • 47
  • 50