A Pipenv porcelain inside Emacs.
Pipenv is a tool that aims to bring the best of all packaging worlds to the Python world. It manages virtual environments, adds and removes packages, and enables deterministic build dependencies.
pipenv.el makes Pipenv a first-class citizen in your Emacs-driven Python development workflow with a range of interactive commands wrapping the Pipenv, a minor mode to accompany
python-mode with a keymap for the most useful commands, and a high-level
pipenv-deactivate interface for virtual environment integration with your Emacs session.
pipenv.el is available on Melpa.
Once installed, all Pipenv commands are available to be called interactively, and are prefixed with
pipenv-. To add the minor mode for buffers with a Python major mode, use
(add-hook 'python-mode-hook #'pipenv-mode).
Here is an example of configuration with
(use-package pipenv :hook (python-mode . pipenv-mode) :init (setq pipenv-projectile-after-switch-function #'pipenv-projectile-after-switch-extended))
pipenv.el wraps the majority of the Pipenv CLI. See all commands prefixed with
pipenv- after installation (
pipenv.el reimplements Pipenv’s
open command in Emacs Lisp as
pipenv-open, rather than shelling out to Pipenv for the logic. This is a design decision, ensuring that modules are opened in the current Emacs session, rather than in
$EDITOR as per the Python implementation of
Activate and Deactivate
In addition to providing the majority of Pipenv commands, there are several custom functions available in
pipenv.el. The most useful are
pipenv-deactivate, which are used to manage the Python virtual environment for the current Emacs session.
pyvenv-activate and sets the variable
python-shell-virtualenv-root to that of the Pipenv project currently being visited, and
pipenv-deactivate sets it back to the Emacs default and also calls
The Pipenv minor mode is activated for buffers with a Python major mode. The minor mode exposes a number of key bindings for
pipenv.el commands, prefixed by
C-c C-p ais bound to
C-c C-p dis bound to
C-c C-p sis bound to
C-c C-p ois bound to
C-c C-p iis bound to
C-c C-p uis bound to
Integration with Flycheck is enabled by default, if Flycheck is installed. The integration customises Flycheck’s
flycheck-executable-find function to search for executables in an activate Pipenv virtual environment.
Disable Flycheck integration with:
(setq pipenv-with-flycheck nil)
Integration with Projectile is enabled by default, if Projectile is installed. The integration adds a hook to
pipenv-projectile-after-switch-function, which can be customized.
Disable Projectile integration with:
(setq pipenv-with-projectile nil)
The default value for
pipenv-projectile-after-switch-function is the function
pipenv-projectile-after-switch-default, which simply activates the Pipenv virtual environment, if a Pipenv project is detected.
You can set your own function to
pipenv-projectile-after-switch-function to customise this behaviour. An example function for this is included, called
pipenv-projectile-after-switch-extended, which, in addition to setting the virtual environment, opens a Pipenv shell, and opens a Python interpreter with
(setq pipenv-projectile-after-switch-function #'pipenv-projectile-after-switch-extended)
pipenv.el relies on pyvenv to switch between different virtual environments (