Emacs Python bottom shell doesn't display prompt after matplotlib show () command

So, I experimented with numpy and matplotlib and came across some error when starting python from the bottom emacs shell.

When I send the py file to the shell interpreter, I can run the commands after the code is executed. The command line "→>" looks fine. However, after I call the matplotlib show command on the chart, the shell just hangs with no command line.

>>> plt.plot(x,u_k[1,:]); [<matplotlib.lines.Line2D object at 0x0000000004A9A358>] >>> plt.show(); 

I am running a traditional C-python implementation. under emacs 23.3 with Fabian Gallina Python python.el v. 0.23.1 on Win7.

A similar question was raised here on the i-python platform: running matplotlib or enthought.mayavi.mlab from the py shell inside emacs in windows

UPDATE: I duplicated the problem on a new installation of Win 7 x64 with typical python 2.7.2 binaries available from the python website, and with numpy 1.6.1 and matplotlib 1.1.0 on emacs 23.3 and 23.4 for Windows.

There should be an error in the emacs shell.

+6
source share
4 answers

I think there are two ways to do this.

  • Use ipython. Then you can use the -pylab option. I do not use Fabian Gallina python.el, but I think you will need something like this:

     (setq python-shell-interpreter-args "-pylab") 

    Read the python.el documentation.

  • You can activate the interactive mode manually ion

     >>> from matplotlib import pyplot as plt >>> plt.ion() >>> plt.plot([1,2,3]) [<matplotlib.lines.Line2D object at 0x20711d0>] >>> 
+1
source

I think this may have something to do with the show function behavior:

matplotlib.pyplot.show (* args, ** kw)

When running in ipython with its pylab mode, display all the numbers and return to the ipython prompt.

In non-interactive mode, display all the numbers and lock until the numbers are closed; in interactive mode, it has no effect, if only numbers were created before changing from non-interactive to interactive mode (not recommended). In this case, it displays numbers, but are not blocked.

One experimental key argument, block, can be set to True or False to override the lock behavior described above.

I think that you have encountered the blocking behavior described above, which will lead to the shell freezing. Perhaps try running a function like: plt.show(block = False) and see if it generates the expected result. If this still gives you problems, let me know and I will try to play your installation locally.

0
source

I think I found an even simpler way to hang the bottom shell, but only when pdb is called. Run pdb by setting "python" as the program to run.

Try this code:

 print "> {<console>(1)<module>() }" 
0
source

After a huge amount of time and posting the error on the matplotlib project page and python mode page, I found that providing console -matplotlib arguments in ipython.bat would do the trick with matplotlib 1.3.1 and ipython 1.2.0

This is what I have in my iphython.bat

@ python.exe -i D: \ devel \ Python27 \ Scripts \ ipython- script.py console --matplotlib% *

0
source

Source: https://habr.com/ru/post/907422/


All Articles