Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get virtualenv to work with fish shell

You don't need to activate to use virtualenv it is a convenience. You can just use the virtualenv directly:

virtualenv venv
./venv/bin/pip install foo

Have you tried from fish using:

. venv/bin/activate.fish

It probably isn't as widely used as bash so may have issues - looking at the commit history shows a recent fix:

https://github.com/pypa/virtualenv/blob/master/virtualenv_embedded/activate.fish


For virtualenv, fish has a separate activation file in the in the bin directory with .fish extension.

So you will have to do:

$ source ~/path/to/bin/activate.fish


You can also use this : https://github.com/adambrenecki/virtualfish

It allows you to activate a virtualenv by typing this :

vf activate <my_env>

You can use virtualfish.

A Fish Shell wrapper for Ian Bicking’s virtualenv, somewhat loosely based on Doug Hellman’s virtualenvwrapper for Bourne-compatible shells.

Source: https://github.com/adambrenecki/virtualfish

Docs: http://virtualfish.readthedocs.org/en/latest/


If you can't use activate.fish, you can just add the bin directory to your PATH:

set -gx PATH /path/to/virtualenv/bin $PATH

That's pretty much all activate.fish does (well, not quite, it also unsets PYTHONHOME, (which wasn't set beforehand when I tried it anyway, YMMV); and it tries to mess with your fish_prompt).

Alternatively: I'm a former Bash user who's started using Fish and misses Doug Hellman's virtualenvwrapper, so I've just today started working on a replacement called virtualfish - it has a few handy shortcuts you might find useful, although it's nowhere near as complete as VEW.


(This thread seems close to be closed, but I found a solution :)

To enter a new fish shell with venv envrionment:

begin; set -lx PATH (realpath ./venv)/bin $PATH; fish; end

when the venv directory is ./venv.

To deactivate, just ctrl-d or exit.


Another solution, which does not invoke a child shell.

Make and enter a venv envrionment:

python3 -m venv ./venv
set -lx PATH (realpath ./venv)/bin $PATH

Exit from the envrionment:

set -lx PATH $PATH[2..-1]