shelper shelper - 2 years ago 182
Python Question

Python shell in Emacs freezes when using matplotlib

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?!

Answer Source

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)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download