【问题标题】:Python shell in Emacs freezes when using matplotlib使用 matplotlib 时 Emacs 中的 Python shell 冻结
【发布时间】:2013-06-14 20:51:50
【问题描述】:

我之前以为是 IPython 的问题,但今天我再次测试,这是我所做的:

  1. 在cmd窗口中运行emacs -Q
  2. 打开一个 .py 文件
  3. M-x,然后运行 ​​python-shell-switch-to-shellRETRET。然后我准备好了 Python shell
  4. 然后我输入以下代码:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> plt.ion()
>>> plt.plot([1,2,3])
[<matplotlib.lines.Line2D object at 0x03068610>]
>>>

实际上在这之后,没有显示任何图形,并且外壳被冻结,例如,当我输入时:

>>> print("hello")

什么都没发生...我没有测试过其他绘图工具,但 matplotlib。我不知道这是否是一个错误。我已经搜索了一段时间,在这里和谷歌,但没有运气。我的系统是:Emacs 24.3 32 bit for Windows,在 Windows 7 下。如果其他人可以复制与此处相同的问题,我将报告此错误。

我使用 IPython 作为 Python shell:

C:/Python27/python.exe -i C:/Python27/Scripts/ipython-script.py --pylab

然后,我输入figure(); plot([1,2,3]),不出所料,图形弹出并冻结。然后我做了:C-c C-d,它运行comint-send-eof,这个数字实际上得到了更新!但我的 IPython shell 会话也因以下消息而终止:

In [6]:
Do you really want to exit ([y]/n)?
Traceback (most recent call last):
File "C:/Python27/Scripts/ipython-script.py", line 9, in <module>
load_entry_point('ipython==0.13.1', 'console_scripts', 'ipython')()
SystemExit

If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True

这里有什么有用的线索吗?!

【问题讨论】:

  • 我在 Fedora 18 上的 GNU Emacs 24.2.1 上尝试过,它工作正常,抱歉。但是我系统上的钩子是python-switch-to-python
  • 您在使用 gui 主循环时遇到问题。你用的是什么后端?尝试将其配置为使用 ipython --pylab 而不是 python
  • @tcaswell 我实际上使用 matplotlib.use() 尝试了不同的后端,但不起作用。但是在cmd窗口中,它可以工作。我也尝试过 ipython,出现了一个图形窗口,但它没有情节就冻结了。我相信这篇文章描述了同样的问题here on Stackoverflow,差不多 1 ​​年过去了,仍然没有真正回答这个问题......我相信它是如果您不介意使用相同的配置尝试它,则可以复制
  • 我没有设置 Windows 框来做任何实际工作。当您启动解释器时,您是否向 python 传递了正确的线程参数? matploblib.use() 需要在导入 plt 之前运行。我怀疑您的系统配置不正确。
  • 这是我在 emacs 中运行 Python shell 的命令:C:/Python27/python.exe -i C:/Python27/Scripts/ipython-script.py --pylab,我的 ipython 是 0.13.2,我的 python 是 2.7.5,默认后端是:TkAgg,正如我所说,它可以工作在 cmd 窗口下,所以我相信这不是后端导致的问题。我也试过 QT。

标签: python emacs matplotlib


【解决方案1】:

一个解决方案是:

(setq python-shell-interpreter "C:\\YourPython3Dist\\python.exe"
      python-shell-interpreter-args "-i C:\\YourPython3Dist\\Scripts\\ipython3-script.py console --pylab=qt")

ipython-script.py 调用中的参数console 是重要的!

在带有 qt 后端的 Python 3 中,它适用于我。我不知道它如何与 py 2.7 一起使用。 (如果ipytho-script.py支持这些参数应该没问题)

【讨论】:

  • 你是让我的生活更轻松的人!它也适用于 python 2.7!
  • 是的,当他们引入控制台参数时,它就开始起作用了。我在 Ipython 1.0 版之前遇到过这个问题
  • @siegfried 我使用的是 WinPython 发行版,而 ipython3-script.py 不在发行版中。知道在这个设置中应该是什么样子吗?我也遇到了同样的挂起行为。
【解决方案2】:

我认为需要一段时间才能解决问题。直到某些 Windows 用户实际调试 python.el。

在那之前,何不试试Emacs IPython Notebook?它是 Emacs 的更好的 IPython 绑定。您不需要使用笔记本部分。您可以将其视为 python.el 中 python shell 的替代品。 (免责声明:我是作者)

【讨论】:

  • 我的经验是 ipython 对 windows 不是很好,笔记本经常出现内核崩溃,我在不同的机器上尝试过,但同样的事情发生了。相信是因为ipython notebook本身需要搭建一个http服务器,在windows下兼容性并不完美。无论如何,感谢 EIN,它是 Emacs 的一个很棒的包,我实际上正在使用它。
  • 如果是内核,问题可能是zmq,而不是http(tornado)。您是否发送了错误报告?我认为 IPython 开发人员在涉及 Windows 时可以更快地解决问题。很高兴你喜欢 EIN :)
  • 如果你有时间,可以帮忙看看问题更新吗?我想知道这是否有助于解决问题,谢谢!
  • 我对python.el内部了解不多,所以不知道怎么解决。我认为您可以向 emacs devel 发送错误报告。
猜你喜欢
  • 2016-04-28
  • 2021-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-10
  • 2017-09-09
  • 2011-12-05
相关资源
最近更新 更多