Note on installing and configuring
elpy in GNU Emacs 26.1 with Python 3.7 on
MacOS Sierra (10.12).
We will obtain
elpy from the MELPA elisp archive. If
.emacs is already configured to use MELPA, skip this step.
Add the following to your
(require 'package) (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/"))
Restart emacs or reload
M-x package-install RET elpy RET to dowload
elpy from MELPA.
When the command completes, add the following to your
Restart emacs or reload
Apply Patches to
When this was written, MELPA provided me with
elpy 1.17.0. In this version,
elpy-config has a bug
when used with Python 3.7 (it seems to work properly with earlier Python
elpy version on github
is 1.24.0. The bug is fixed in this version.
Rather than attempt to install the newer version from github, I chose to patch
elpy.el with the fix
from github -- it is only two lines of code.
~/.emacs.d/elpa/elpy-1.17.0, I recompiled the file via
M-x byte-compile-file RET elpy.el RET.
Without this fix,
elpy-config would fail after installing some of the Python
Specifying the virtualenv
Prior to configuring
elpy, you must ensure that your venv is set
For this example, I am using a venv named
Set the venv via
M-x pyvenv-workon RET py37 RET. Obviously, this relies
$WORKON_HOME being set properly by
Alternatively, you can activate a specific venv. My
$WORKON_HOME is set to
~/.virtualenvs. I could have activated
M-x pyvenv-activate RET ~/.virtualenvs/py37.
This is a side note / tip, not necessary to configure
.dir_locals.el file can be used to automatically set the venv within
Emacs for a python project. Typically, the file is placed in the root of a
Python project and applies itself to all subdirectories.
For example, the following
.dir_locals.el, when placed in the root of a
Python project, sets the venv to
py37 in the root and all subdirectories:
;;; Directory Local Variables ;;; For more information see (info "(emacs) Directory Variables") ((python-mode . ((pyvenv-workon . "py37"))))
N.B.: Ensure your venv is correct. You can check it via:
M-: pyvenv-virtual-env-name RET. In my case, it returns "py37".
elpy provides the
elpy-config command to simplify configuration.
Run it via:
M-x elpy-config RET. It may run a few seconds before opening a
Install Missing Python Packages
Any Python packages that are required by
elpy, but that are not present in
the venv, will be displayed near the top of the buffer, just below
The current configuration will be displayed in the top of the buffer. If any of the required Python packages are not present in the venv, they will be shown as missing in the configuration.
When packages are missing, the buffer will display content that, when clicked, will install the packages into the current venv. To install a package, click on '[run]' in the buffer.
Of course, all of these packages could have been installed in the venv
using 'pip', without using Emacs or
elpy has a large number of options that can be configured. The remainder of
the buffer provides the ability to tweak these options.