Python shell in Emacs freezes when using matplotli

2020-02-11 06:27发布

I previously thought that was the issue with IPython, but today I tested again, here is what I did:

  1. Run emacs -Q in cmd window
  2. Open a .py file
  3. M-x, then run python-shell-switch-to-shell, RET, and RET. Then I have the Python shell ready
  4. 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?!

2条回答
家丑人穷心不美
2楼-- · 2020-02-11 07:05

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)

查看更多
叼着烟拽天下
3楼-- · 2020-02-11 07:16

I think it would take sometime until the problem is fixed. Until some Windows user actually debugs python.el.

Until then, why not try Emacs IPython Notebook? It is a better IPython binding for Emacs. You don't need to use the notebook part. You can think it as a replacement for python shell in python.el. (disclaimer: I am the author)

查看更多
登录 后发表回答