How to get virtualenv to work with fish shell?
VirtualenvFishVirtualenv Problem Overview
I'm trying to get virtualenv to work with the fish shell. I have virtualenv installed and it works fine with bash and zsh. However, running the following command returns fish: Unknown command 'source'
:
$ source ~/path/to/bin/activate
Does anyone know how to get virtualenv and the fish shell to work together?
Virtualenv Solutions
Solution 1 - Virtualenv
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
Solution 2 - Virtualenv
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
Solution 3 - Virtualenv
You can also use this : https://github.com/adambrenecki/virtualfish
It allows you to activate a virtualenv by typing this :
vf activate <my_env>
Solution 4 - Virtualenv
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.
Solution 5 - Virtualenv
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.
Solution 6 - Virtualenv
(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]
Solution 7 - Virtualenv
If it's an env file try this .env/bin/activate.fish make sure your env file is inside your project file, in my case it's a django project. Tt worked for me
Solution 8 - Virtualenv
You can use the command - set VIRTUAL_ENV 'path to the virtual env directory'
Example - set VIRTUAL_ENV '/home/aman/Desktop/test/venv'