Live coding in Python with PyCharm, Emacs, Sublime Text, or even a browser
MIT License
Visualize your Python code while you type it in PyCharm, Emacs, Sublime Text, or even your browser.
Live coding tightens the feedback loop between making a change to your code and seeing the behaviour change. As you type your code, it will run over and over, showing a visualization of the program state, a matplotlib graph, a Pillow image, or turtle graphics. If you make a mistake, you'll immediately see the problem and where it went wrong.
To see how to use one of the Live Coding in Python plugins, watch the demo video or read the getting started pages for PyCharm, Emacs, or Sublime Text. Want to try it without installing anything? Try the browser version. You can also try Space Tracer, the command-line tool that trades time for space when you debug. You might also find some useful examples in the tools folder. To learn more, read about how it works.
Special thanks to James Davies for contributing the Sublime Text support, to Antti Kaihola and Christoph Paulik for contributing the Emacs support, and to Brecht Willems for the idea of flag tutorials. Thanks to all the contributors for helping in all kinds of ways, and thanks to JetBrains for the free PyCharm and IDEA licenses.
If you like this project, check out some of my other projects.
So far, the Emacs mode seems to be the most popular way to use live coding in Python, and the PyCharm plugin has the most features. The browser version might be the best for students, because it has tutorials and doesn't need to be installed.
Feature | PyCharm | Emacs | Sublime | browser | space_tracer |
---|---|---|---|---|---|
variable assignments | Y | Y | Y | Y | Y |
looping | Y | Y | Y | Y | Y |
function calls | Y | Y | Y | Y | Y |
errors and exceptions | Y | Y | Y | Y | Y |
print function | Y | Y | Y | Y | Y |
unit tests | Y | Y | Y | Y | |
turtle graphics | Y | Y | |||
matplotlib preview | Y | Y | |||
pyglet preview | Y | Y | |||
tutorials and goals | Y |
If you find the project useful, help us make it better.
This assumes you already have PyCharm installed, you have configured a Python interpreter, and you can run a Python script normally.
It's probably easiest to use the MELPA package archive, as described in this section, but the next section gives instructions for installing without MELPA.
M-x package-list-packages
.C-s live-py-mode
. If you can't find it, runM-x package-refresh-contents
, and try again.i
, then execute the installation withx
.M-x live-py-mode
.C-h m
and scroll down to the Live-Py section to see all theInstall GNU Emacs if you don't already have it.
Clone the latest version of the live-py Emacs mode:
git clone https://github.com/donkirkby/live-py-plugin.git
Copy the Emacs Lisp file and the supporting Python files into a directory
which is in your Emacs load-path
. For example:
cd live-py-plugin
mkdir -p ~/.emacs.d/packages
cp emacs-live-py-mode/live-py-mode.el plugin/PySrc/space_tracer ~/.emacs.d/packages
Add ~/.emacs.d/ to your load-path
in ~/.emacs.d/init.el
or ~/.emacs
:
(add-to-list 'load-path "~/.emacs.d/packages")
Load the Lisp library in your ~/.emacs.d/init.el
or ~/.emacs
:
(require 'live-py-mode)
Restart Emacs.
Open any Python file, and activate live-py-mode with M-x live-py-mode
.
You should see an extra window on the right that shows the results of running
your code.
Type C-h m
and scroll down to the Live-Py section to see all the
advanced features that let you run other versions of Python or drive your
live coding from another script or a unit test.
If you installed with MELPA, just use it to uninstall. If not, follow these steps:
~/.emacs.d/
:~/.emacs.d/init.el
or ~/.emacs
.It's easiest to install from package control, but you can find a manual method in the CONTRIBUTING file.
python
.