python - wx无法在mac上运行

标签 python macos wxpython anaconda

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

import wx
app = 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.

我使用 script :

#!/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 "$@"

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

最佳答案

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

我的环境是:

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

提示:

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

关于python - wx无法在mac上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39989975/

相关文章:

python - 在 ubuntu 16.04 上安装 wxPython 需要很长时间

python - 如何在 wxpython 中使用命名颜色?

python - 如何从内存数据创建一个 wx.Image 对象?

python - 将纪元时间转换为日期时间

python - Django-Haystack 没有返回确切的查询

objective-c - 如何填充 NSTableView?

macos - Mac 上的 Pip 安装失败

macos - 奇怪的行为 NSBitmapImageRep

python - 如何在keras中指定相关系数作为损失函数

python - Scrapy从论坛爬取数据