7

I noticed that I can't use virtualenvwrapper commands (like workon) in an eshell but they do work within a shell environment. Is there a virtualenvwrapper-like mode for Emacs?

4

virtualenvwrapper (in melpa) gives the command venv-workon to switch environment, but for all emacs session too. It works with eshell with venv-initialize-eshell:

support for eshell is turned on by calling venv-initialize-eshell. After doing this, any new eshells you launch will be in the correct virtualenv and have access to installed executables, etc. The mode also provides a variety of virtualenvwrapper commands that work identically to their bash/zsh counterparts (described in detail below). Note that in contrast to how interactive shells work, Eshell shares an environment with Emacs, so if you activate or deactivate in one, the other is affected as well. Note that this requires the variable eshell-modify-global-environment to be set to true. Running venv-initialize-eshell causes this to occur. If this doesn't work for you, open an issue! It's technically possible to separate the two, but it requires some hacking around with the different namespaces that I won't bother to do unless someone really needs it.

and on modifying the eshell prompt:

Eshell prompt customization

You also might want to have the name of your current virtualenv appear on the eshell prompt. You can do this by a pretty similar mechanism, just include venv-current-name in your eshell-prompt-function somewhere. Here is a simple example of a prompt that includes the current virtualenv name followed by a dollar sign:

(setq eshell-prompt-function (lambda () (concat venv-current-name " $ ")))

Make sure you also adjust your eshell-prompt-regexp if you do this.

More about customizing the eshell prompt on the EmacsWiki.

Works with (e)shells, has auto-activation, displays in the mode line.

I would be interested to know the differences betwwen it and pyvenv.

2

pyvenv lets you use a virtualenv from within Emacs. Note however that due to some limitations of Emacs this package switches your entire Emacs session to a specific virtualenv. If I remember correctly, it is not possible to switch just one buffer to a virtualenv.

  • I typically use my .dir-locals.el to switch the pyvenv per-project. pyvenv also has a tracking setting to switch automatically when switching buffers. – elarson Nov 25 '14 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.