Automatically activates python virtualenv on emacs using:
python-version
file in the project root..venv
orvenv
directory (or link) in the project root.- Try find a virtualenv with the same name of Project Root.
Project root is defined as a parent directory containing auto-virtualenvwrapper-project-root-files
. By default the variable equals to (".python-version" ".dir-locals.el" ".projectile" ".emacs-project" "manage.py" ".git" ".hg")
.
This code is based on auto-virtualenv, but uses tiny virtualenvwrapper library rather then pyenv. This way you avoid additional dependencies: pyenv and elpy.
M-x package-install [RET] auto-virtualenvwrapper [RET]
Clone this repository somewhere and add this directory to you
load-path
.
(require 'auto-virtualenvwrapper)
(add-hook 'python-mode-hook #'auto-virtualenvwrapper-activate)
Optionally:
;; Activate on changing buffers
(add-hook 'window-configuration-change-hook #'auto-virtualenvwrapper-activate)
;; Activate on focus in
(add-hook 'focus-in-hook #'auto-virtualenvwrapper-activate)
View official GNU site http://www.gnu.org/licenses/gpl.html.