shelper shelper - 3 years ago 225
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
    , and
    . 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/ --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
, 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/", line 9, in <module>
load_entry_point('ipython==0.13.1', 'console_scripts', 'ipython')()

If you suspect this is an IPython bug, please report it at:
or send an email to the mailing list at

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\\ console --pylab=qt")

The Argument console in the call of 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

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