I\'m trying to run Python code for testing and debugging using Emacs. How should I debug and run code in *.py files ? I tried using the M-x compile
commands . U
In my opinion, M-! and M-& are underrated. Often you just want to start the current script you are working on, no need to complicate things.
Of course, you can use M-x compile
, as long as you don't have to provide interactive input. If you do have to provide interactive input, M-x shell
is your friend.
If you want to run stuff with one button press, check out F3 and F4 to record a keyboard macro and replay it (the macro can also be bound to a key, e.g. F5).
In each of these cases, there is no "magic" taking place. Emacs does not know how to "compile" or "run" python scripts. You have to provide/overwrite a sensible command line invocation, like:
Compile Command: ipython .py
The python subshell is cool where a REPL development style makes sense, but at least on Windows matplotlib
, tkinter
and other libraries that have to deal with the Windows Message Loop tend to block/hang upon displaying GUI elements.