direnv
is a small but nifty tool that optimizes the task of switching to the right virtualenv
1. Install direnv
sudo apt-get update
sudo apt-get install direnv
2. Add the snippet below in Your .bashrc
/.zshrc
show_virtual_env() {
if [ -n "$VIRTUAL_ENV" ]; then
echo "($(basename $VIRTUAL_ENV))"
fi
}
PS1='$(show_virtual_env)'$PS1
# direnv
eval "$(direnv hook bash)"
3. Add .direnvrc
to your home folder
Copy this snippet to the .direnv that You just created
Javascriptlayout_virtualenv() {
local venv_path="$1"
source ${venv_path}/bin/activate
}
4. Add .envrc
in your project folder for instance in /home/faisal/myproject
and copy the snippet below into the file
Javascriptlayout virtualenv ~/myproject/myproject-env
That's it! Happy coding.