wxPython 需要什么才能成功运行?

mpo*_*ett 7 macos wxpython python-3.x pyenv

我正在尝试让 wxPython 在pyenv基于virtualenvvirtualenvwrapper插件的基于虚拟环境中工作在MacOS 上。我已经阅读了几个关于如何完成这项工作的问题,但大多数答案似乎都假设我使用的是系统 python 版本,和/或只解决了一个损坏设置的一个方面。我还没有看到任何解释 wxPython 在启动时检查什么的内容。

我有 pyenv 编译的 python 3.7 与--enable-framework.

env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.4
Run Code Online (Sandbox Code Playgroud)

pyenv 它本身是从 git 中最近(在过去几周内)拉取的,安装在我的 homedir 中。

需要明确的是,我的 Python 工具链中的任何工具或库都不是 Homebrew 安装的。

我的 virtualenv 可以通过--system-site-packages. 据推测,访问框架和显示是 wxPython 工作所需的全部内容,但在任何测试应用程序启动时,我仍然遇到相同的错误:

该程序需要访问屏幕。请使用 Python 的框架版本运行,并且仅当您在 Mac 的主显示屏上登录时才运行。

在我看来,我应该需要的一切都可用。

% pyenv which python3.7
/Users/matt/.pyenv/versions/3.7.4/bin/python3.7

% mkvirtualenv --system-site-packages --python python3.7 wxtest
Running virtualenv with interpreter /Users/matt/.pyenv/shims/python3.7
Already using interpreter /Users/matt/.pyenv/versions/3.7.4/Python.framework/Versions/3.7/bin/python3.7
Using base prefix '/Users/matt/.pyenv/versions/3.7.4/Python.framework/Versions/3.7'
New python executable in /Users/matt/.ve/wxtest/bin/python3.7
Also creating executable in /Users/matt/.ve/wxtest/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/get_env_details

% python -m site
sys.path = [
    '/Users/matt/devel/wxtest',
    '/Users/matt/.ve/wxtest/lib/python37.zip',
    '/Users/matt/.ve/wxtest/lib/python3.7',
    '/Users/matt/.ve/wxtest/lib/python3.7/lib-dynload',
    '/Users/matt/.pyenv/versions/3.7.4/Python.framework/Versions/3.7/lib/python3.7',
    '/Users/matt/.ve/wxtest/lib/python3.7/site-packages',
    '/Users/matt/.pyenv/versions/3.7.4/Python.framework/Versions/3.7/lib/python3.7/site-packages',
]
USER_BASE: '/Users/matt/.local' (exists)
USER_SITE: '/Users/matt/.local/lib/python3.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: True

% pip install wxPython
Collecting wxPython
[...]
Successfully installed numpy-1.18.0 pillow-6.2.1 six-1.13.0 wxPython-4.0.7.post2
Run Code Online (Sandbox Code Playgroud)

的代码IsDisplayAvailable()隐藏在_core共享对象库中,因此不是特别容易检查。我不是 C++ 编码员,我在代码库中挖掘到目前为止我能找到的只是 中的文档字符串src/_app.i,而不是实际代码。

  • 在 Mac OS X 上,False返回值意味着 wx 无法访问窗口管理器,如果远程登录或从普通版本的 python 而不是框架版本(即 pythonw)运行,就会发生这种情况。

我在这里所拥有的似乎满足了该要求清单。我没有pythonw二进制文件,但正如pythonw(1)手册页所说:

实际上,从 Python 2.5 开始,普通的 python 也允许 GUI 访问,所以现在 python 和 pythonw 可以互换。

有没有人对 wxPython 在运行之前实际期望找到的内容有详尽的列表?

ZF0*_*007 2

您遇到的错误可能是“酒洞”(也称为 wxpython v3 和有时 v4 的自制安装/兼容性问题)。

要测试可能出现的一些问题,请在 pyenv 中执行以下操作:

  1. python --version
  2. python3 --version

它们是如何安装的?你用过酿造吗?

  1. 如果是brew或任何非anaconda:全部卸载。

  2. 然后:通过 anaconda 2019.(xx >04) 打包版本重新安装 python,它会根据您的选择为您提供 3.7.4 或 3.7.5。

  3. 通过 conda/pip 命令行重新安装默认安装中未安装的所需软件包。

Anaconda“base”是您的默认环境。

  1. 其中conda create --name myenvmyenv 是您为环境指定的任何名称。例如“myPythonwx408”环境。
  2. 命令行:conda activate myenv

...还有tada..你走吧...

如果错误仍然存​​在于 anaconda env 中,您可以发布environment.yml 文件,以便我可以重新创建您的环境进行测试。