python - 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 的。
解决方案
使用 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
推荐阅读
- model-view-controller - 使用 Laravel 5.5 登录后传递共享变量
- trace - 如何使用 perf 探针打印 malloc 大小函数
- ios - 如何指定弹出框控制器的箭头指向的位置
- python - 在 django 中上传时使用 pil 调整图像大小
- java - 使用单元测试检查 Clojure 代码的架构
- c - C中realloc函数的时间复杂度是多少?
- c# - 在 asp.net webform 页面中注册 Src 属性并阻止 c# 代码
- angular - 如何从 Angular 组件设置(单击)属性
- amazon-redshift - 从 Redshift 导入 Sqoop
- regex - 使用 CFML 删除特定的 HTML 标签