首页 > 解决方案 > wxpython-phoenix 需要 osx/ipython/pycharm 上的 python 框架

问题描述

运行wxpython-phoenix 网站上提供的示例 hello-world 代码会在 osx 上引发已知错误。可以在此处此处找到可能解决方案的提示,但似乎没有一个适用于 ipython 和 pycharm。

问题:如何在 pycharm 中使用 ipython 来解决这个已知错误?

设置:

conda venv pycharm CE 2018.3中的OSX 10.12.5 Sierra
ipython 3.7.1 (命令行和 jupyter notebook 也失败)

代码运行:(来自 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.

注意:这个问题类似于:
-那个是针对 python2.7 的,但没有收到答案
-一个在 pycharm 之外为常规 python 提供过时修复的
问题 像这样的其他问题,对于新版本来说已经过时了wxpython 的。

标签: pythonpython-3.xmacospycharmwxpython

解决方案


使用 conda 环境时,您需要安装python.app包,然后使用它pythonw来运行使用 wxPython 的应用程序。

在 osx 上,命令行是:(如此处所示

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

推荐阅读