While working with python, you always need to use virtual environments.

And for the folks like me, who uses fish shell instead of other shell. Activating the virtualenv might be a little tricky.

The following method does not work in fish but it works in other shells like Bourne Shell, zsh.

1
2
3
4
5
6
7
8
$ source /Path/to/venv/bin/activate
/Path/to/venv/bin/activate (line 76): Missing end to balance this if statement
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
^
from sourcing file ~/.venvs/lpthw/bin/activate
        called on standard input

source: Error while reading file “/Path/to/venv/bin/activate”

If you cd into the virtualenv directory and ls you can see as:

1
2
3
4
5
$ cd /Path/to/venv/bin/
/bin/$ ls
activate       activate_this.py   pip*     python*     python-config*
activate.csh   easy_install*      pip3*    [email protected]    wheel*
activate.fish  easy_install-3.7*  pip3.7*  [email protected]

See there?

There is a file named activate.fish.

Thanks to latest virtualenv for including the file for different shells.

$ source /Path/to/venv/bin/activate.fish And that’s it. That’s the magic.