wx 无法在 mac 上运行

Xia*_*hai 6 python macos wxpython anaconda

我在 mac 上安装了 anaconda 而不是系统的 python,但是当我输入时

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

我懂了:

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

我使用脚本

#!/bin/bash

# what real Python executable to use
PYVER=2.7
PYTHON=/Library/Frameworks/Python.framework/Versions/$PYVER/bin/python$PYVER

# find the root of the virtualenv, it should be the parent of the dir this script is in
ENV=`$PYTHON -c "import os; print os.path.abspath(os.path.join(os.path.dirname(\"$0\"), '..'))"`

# now run Python with the virtualenv set as Python's HOME
export PYTHONHOME=$ENV 
exec $PYTHON "$@"
Run Code Online (Sandbox Code Playgroud)

但它只是使用系统python。不能在anaconda中使用lib。我想在anaconda中使用wx GUI,如何解决问题?

Ala*_*eng 4

我通过阅读这篇文章解决了我的 Python 2 和 3 虚拟环境的问题(请参阅下面的提示):

我的环境是:

  • macOS 10.12.5
  • 通过 Homebrew 安装 Python 2
    • wxPython 通过以下方式安装:brew install wxpython
  • 通过 Homebrew 安装 Python 3
    • wxPython 通过以下方式安装: gpip3 install wxpython (Python 3 的全局 PIP)

尖端:

  • 您可以修改该帖子中的脚本以适用于 Python 3。
  • 如果您不使用 virtualenvwrapper,则应在“activate”文件中设置“PYTHONHOME”而不是“postactivate”。