wxPython:这个程序需要访问屏幕

duh*_*ime 9 python wxwidgets wxpython

我正在尝试在以下最小应用程序中使用 Python GUI wx(可通过 安装pip install wxPython):

import wx
app = wx.App()
Run Code Online (Sandbox Code Playgroud)

运行此代码段将返回以下内容:

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)

有谁知道如何帮助 wx 获得“访问屏幕”,或者什么是“Python 框架构建”?如果其他人可以为这些问题提供任何帮助,我将不胜感激!

Nic*_*mer 10

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
Run Code Online (Sandbox Code Playgroud)

^请参阅 Python 文档中以下页面中的“4.1.2 使用 GUI 运行脚本”部分(在 MacOS 上)以查看此 Python 怪癖的解释:https : //docs.python.org/3/using/mac.html


duh*_*ime 7

这解决了问题,但它不能是最漂亮的解决方案:

# 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
Run Code Online (Sandbox Code Playgroud)