在Python 3 Miniconda环境中使用wxPython
我在OS X上尝试使用wxPython Phoenix和Python 3.3。(我不太确定Phoenix支持哪个版本的Python 3,我是强制安装的。)
>>> 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.
现在我看到这篇文章,里面说wxPython在使用virtualenv时会有问题,并提供了一个脚本来解决这个问题:
#!/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 "$@"
我看不懂BASH($@是什么?)但看起来只是需要设置PYTHONHOME。我是在Python 3上运行wxPython Phoenix,而不是Python 2。而且我没有使用virtualenv,我用的是Miniconda。我不知道该把PYTHONHOME设置在哪里。我把它设置成了PYTHONHOME="/Users/username/miniconda3/",但是没有效果。
1 个回答
4
一个更好的解决办法是使用 pythonw
,你可以安装 python.app
这个conda包,而不是直接使用 python
。