I always had it working, including after update to Catalina and I never needed to run some silly pythonw
instead of python
and had all my wx-enabled scripts running correctly.
At some time something broke in my environment, I think it was the pip-tools
that without any warning started to remove my packages. Not sure what happened but damage has been done and suddenly I saw the infamous
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 manage my environments with pyenv
, the current python environment was 3.4.7
. Let the script from the question be tst.py
, I run
$ python tst.py
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 make sure the wxpython
is installed with brew
$ brew info wxpython
wxpython: stable 4.1.1 (bottled)
Python bindings for wxWidgets
https://www.wxpython.org/
/usr/local/Cellar/wxpython/4.1.1 (1,227 files, 91.8MB) *
Poured from bottle on 2021-03-04 at 14:52:18
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/wxpython.rb
License: LGPL-2.0-or-later with WxWindows-exception-3.1
==> Dependencies
Required: freetype ✔, jpeg ✔, libpng ✔, libtiff ✔, numpy ✔, python@3.9 ✔
==> Analytics
install: 643 (30 days), 2,701 (90 days), 12,659 (365 days)
install-on-request: 604 (30 days), 2,523 (90 days), 9,914 (365 days)
build-error: 0 (30 days)
The wxPython wiki suggests
The reason is because some 3rd party tools like PyInstaller might require CPython installation be built with --enable-framework. What you need to do is run $ env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.x.x in your terminal.
so I re-installed 3.7.4
from scratch
$ pyenv uninstall 3.7.4
$ env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.4
and tried the script again
$ python tst.py
2021-03-04 15:14:44.138 Python[18815:404240] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
of course it does not completely resolves it but at least the annoying error is gone...