运行wxpython-phoenix website上提供的示例hello-world代码会在osx上引发已知错误。有关可能的解决方案的提示可以找到here和here,但似乎没有一个与ipython和pycharm一起使用。
问题:如何使用pycharm中的ipython解决这个已知错误?
建立:
OSX 10.12.5 Sierra 在conda venv中的ipython 3.7.1 pycharm CE 2018.3 (也从命令行和jupyter笔记本中失败)
代码运行:(从wxpython入门页面)
import wx
app = wx.App()
frm = wx.Frame(None, title="Hello World")
frm.Show()
app.MainLoop()
错误信息
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.
完全追溯
---------------------------------------------------------------------------
SystemExit Traceback (most recent call last)
<ipython-input-1-5af94fb54276> in <module>
3
4 # Next, create an application object.
----> 5 app = wx.App()
6
7 # Then a frame.
~/anaconda3/envs/py37/lib/python3.7/site-packages/wx/core.py in __init__(self, redirect, filename, useBestVisual, clearSigInt)
2100 # TODO: more description is needed for wxMSW...
2101
-> 2102 raise SystemExit(msg)
2103
2104 # This has to be done before OnInit
SystemExit: 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.
注意:这个问题类似于: - that一个用于python2.7,但没有得到答案 - that一个在pycharm之外提供常规python的过时修复 其他问题如this one,对于wxpython的新版本已经过时了。
使用conda环境时,您需要安装python.app
软件包,然后使用pythonw
运行使用wxPython的应用程序。
在osx上,命令行是:(如图所示here)
conda install -c anaconda python.app
您将看到以下消息;确认继续。
The following packages will be SUPERSEDED by a higher-priority channel: python.app: 2-py37_9 --> 2-py37_9 anaconda
使用pycharm,有必要更改项目解释器:
- >转到:
preferences
project interpreter
add interpreter
conda environment
anaconda (or anaconda3)
bin
pythonw
select pythonw
apply
ok