如何让 Virtual alenv 与鱼壳一起工作?

我正在试着让 Virtual alenv 和鱼壳一起工作。我已经安装了 viralenv,它可以很好地使用 bash 和 zsh。但是,运行以下命令将返回 fish: Unknown command 'source':

$ source ~/path/to/bin/activate

有人知道如何让 viralenv 和鱼壳一起工作吗?

49207 次浏览

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

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.

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/

(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]

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

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

You can use the command - set VIRTUAL_ENV 'path to the virtual env directory' Example - set VIRTUAL_ENV '/home/aman/Desktop/test/venv'