Integrate pyenv with python-mode.
Emacs Lisp
Latest commit 560614d Feb 21, 2016 @proofit404 Update Copyright year.
Failed to load latest commit information.
.gitignore Init repo. Mar 6, 2014
README.rst Unset environment in the projectile snippet. Fix #23 Dec 12, 2015
pyenv-mode.el Update Copyright year. Feb 21, 2016


Pyenv mode


Integrate Fabián E. Gallina python.el with pyenv tool. This allow packages which already use python.el (like python-django) got pyenv virtual environments support out-of-the-box.

Pyenv mode does...

  • Setup PYENV_VERSION environment variable and python-shell-virtualenv-path custom variable based on user input

Pyenv mode doesn't...

  • Override your exec-path
  • Run external shell scripts
  • Manage your pyenv installation
  • Deal with virtualenvwrapper


You can simply install package from Melpa:

M-x package-install RET pyenv-mode


Add following block to your emacs configuration


Now you are available to specify pyenv python version:

M-x pyenv-mode-set

So now when you run inferior python with:

M-x run-python

process will start inside specified python installation. You can unset current version with:

M-x pyenv-mode-unset


When you set python version with pyenv-mode following changes happens automatically

  • compile commands use proper python version and environment
  • flycheck perform syntax checking according to python version you use
  • anaconda-mode search completions, definitions and references in chosen environment

Projectile integration

You can switch python version together with current project. Drop following lines into emacs init file. When use projectile switch project with C-c p p key binding pyenv-mode will activate environment matched project name.

(require 'pyenv-mode)

(defun projectile-pyenv-mode-set ()
  "Set pyenv version matching project name."
  (let ((project (projectile-project-name)))
    (if (member project (pyenv-mode-versions))
        (pyenv-mode-set project)

(add-hook 'projectile-switch-project-hook 'projectile-pyenv-mode-set)