使用 matplotlib 时 Emacs 中的 Python shell 冻结 [英] Python shell in Emacs freezes when using matplotlib
问题描述
我之前认为这是 IPython 的问题,但今天我再次测试,这是我所做的:
- 在cmd窗口中运行
emacs -Q
- 打开一个 .py 文件
M-x
,然后运行python-shell-switch-to-shell
、RET
和RET
.然后我准备好了 Python shell- 然后我输入以下代码:
<块引用>
Python 2.7.3(默认,2012 年 4 月 10 日,23:31:26)[MSC v.1500 32 位(英特尔)] on win32输入帮助"、版权"、信用"或许可证"以获取更多信息.>>>导入 matplotlib.pyplot 作为 plt>>>plt.ion()>>>plt.plot([1,2,3])[]>>>
实际上在这之后,没有任何图形出现,并且外壳被冻结,例如,当我输入时:
<块引用><预><代码>>>>打印(你好")什么也没发生...我没有测试过其他绘图工具,但 matplotlib.不知道是不是bug我已经在这里和谷歌搜索了一段时间,但没有运气.我的系统是:Emacs 24.3 32 位 for Windows,在 Windows 7 下.如果其他人可以复制与这里相同的问题,我会将其报告为错误.
我使用 IPython 作为 Python shell:
C:/Python27/python.exe -i C:/Python27/Scripts/ipython-script.py --pylab
然后,我输入figure();plot([1,2,3])
,正如预期的那样,图形弹出并冻结.然后我做了:运行 comint-send-eof
的 C-c C-d
,这个数字实际上得到了更新!但是我的 IPython shell 会话也被终止并显示以下消息:
在 [6] 中:你真的要退出 ([y]/n) 吗?回溯(最近一次调用最后一次):文件C:/Python27/Scripts/ipython-script.py",第 9 行,在 <module>load_entry_point('ipython==0.13.1', 'console_scripts', 'ipython')()系统退出如果您怀疑这是 IPython 错误,请在以下位置报告:https://github.com/ipython/ipython/issues或发送电子邮件至 ipython-dev@scipy.org 的邮件列表您现在可以使用%tb"打印更详细的回溯,或使用%debug"以交互方式调试它.可以通过以下方式启用用于错误报告目的的额外详细回溯:%config Application.verbose_crash=True
这里有什么有用的线索吗?!
一种解决方案是:
(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
支持这些参数,应该没问题)
I previously thought that was the issue with IPython, but today I tested again, here is what I did:
- Run
emacs -Q
in cmd window - Open a .py file
M-x
, then runpython-shell-switch-to-shell
,RET
, andRET
. Then I have the Python shell ready- I in put the following code then:
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>] >>>
Actually after this, no figure shows up, and the shell is frozen, e.g., when I input:
>>> print("hello")
nothing happened...I haven't tested other plotting tools but matplotlib. I don't know if it is a bug. I've searched for a while, here and though Google, but no luck. My system is: Emacs 24.3 32 bit for Windows, under Windows 7. If others can duplicate same issue as here, I will report this as a bug.
I used IPython as the Python shell by:
C:/Python27/python.exe -i C:/Python27/Scripts/ipython-script.py --pylab
Then, I input figure(); plot([1,2,3])
, as expected, the figure popup and freezes. Then I did: C-c C-d
which runs comint-send-eof
, and the figure actually get updated! But my IPython shell session is also terminated with the following message:
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
Any helpful clue here?!
one solution is:
(setq python-shell-interpreter "C:\YourPython3Dist\python.exe"
python-shell-interpreter-args "-i C:\YourPython3Dist\Scripts\ipython3-script.py console --pylab=qt")
The Argument console
in the call of ipython-script.py is the important one!
In Python 3 with qt backend it works for me. I don't know how it works with py 2.7. (should be no problem if these arguments are supported for ipytho-script.py
)
这篇关于使用 matplotlib 时 Emacs 中的 Python shell 冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!