如何在 macOS 12.4 (Monterey) 上使用 python.org 安装程序运行 wxPython

And*_*per 3 python macos

我想从 python.org 安装 python 并让它在 macOS 的终端中与 wxPython 一起使用:

  • 使用 macOS 64 位 universal2 安装程序安装 python 3.9.13
  • 使用 pip 安装 wxPython -pip3 install -U wxPython
  • 在 shell 中启动 python 并尝试启动 wx 应用程序:
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.
Run Code Online (Sandbox Code Playgroud)

请不要将我指向brew、pyenv、anaconda 或框架构建——我希望上述组合能够工作,但似乎不行。从 python.org 下载的一个框架构建,如果我从 IDLE 运行它,它使用完全相同版本的 python 可以正常工作,所以感觉它一定是一些 macOS 安全问题或 shell/python 交互

Gar*_*son 6

升级到蒙特利后,我在现有代码库上遇到了这个问题。

我的应用程序在使用 py2app 构建时仍然可以工作,但从命令行运行时就不行了。

看起来底层的 wxWidgets 方法IsDisplayAvailable开始失败,所以我只是删除了检查。

它位于您的站点包中wx/core.py,第 2183 行。

改变

   if not self.IsDisplayAvailable():
Run Code Online (Sandbox Code Playgroud)

   if False:
Run Code Online (Sandbox Code Playgroud)

你就可以去参加比赛了。

我能说什么?虽然很脏,但我又开始工作了。