background preloader

Emacs

Facebook Twitter

Running Python from within Emacs. Emacs python mode supports running scripts in an inferior python process that is running in an emacs buffer.

Running Python from within Emacs

I really like this idea but have never been able to reliably use it because so much of my work depends on external libraries that may not do a complete job of cleaning up their state. Attempting to reuse them in the same process is, in my experience, a recipe for confusion. Also, emacs seems to be hung waiting on the python subprocess while my GUI app is running. As a result, I always edit in emacs and then switch to a command prompt to run. It occurred to me that if I my program doesn't need input (almost all mine have a GUI) I can run them using the emacs compile command. In my .emacs file I defined this function (defun my-compile () "Use compile to run python programs" (interactive) (compile (concat "python " (buffer-name)))) (setq compilation-scroll-output t) This function invokes compile with python foo.py when I'm editing a buffer named foo.py.

I'm loving this! Emacs for Python Programmers: Basics. At PyCon I noticed the usual discussion of IDEs, editors, and programming environments. There seems to be some sort of strange equilibrium going on whereby programmers are constantly fussing, switching and growing discontented with their programming editors. I've used Emacs for almost 10 years now and other than a brief (forced) stint with CodeWarrior in college, it has been my primary editor for coding, blogging, journaling. I even wrote a book in it. But I'll admit, Emacs isn't exactly sexy and it certainly has a steep learning curve. I don't generally advocate it to people unless I think they'll have the patience to learn it.

There are also "real" IDEs like TextMate, Eclipse, Visual Studio, etc. The goal of this series of posts is to help resolve some of the mysteries people struggle with when switching to Emacs for Python development. Emacs: What to Install Emacs comes in (roughly) two varieties: GNU Emacs and XEmacs. There are too many differences between these Emacsen to go over. Python Programming In Emacs. This page collects information for creating a usable Python programming environment in Emacs.

Python Programming In Emacs

Python Modes There are a number of Python modes for Emacs. The major ones are python.el which comes with Emacs 24.2 and up and python-mode.el, which is the most comprehensive; it integrated most of the stuff discussed below. The older python.el from Emacs 24.1 and before has a number of fans as well. Emacs as a Python IDE Beyond the basic Python modes described above, there are a number of modes that support Python programming. Emacs for Python, a collection of emacs extensions specifically collected for python development, with workflow guidelines.Elpy, an Emacs Python development environment available via package.el as a simple installation. Other Support Modes Video from EuroPython? Various Python Interpreters IPython python-mode.el comes with IPython support, setup as shown below has been integrated. Emacs’ 24.2+ python.el contains the following guide on how to set it up to use IPython 0.11: