VirtualEnv

Last modified by David De La Harpe Golden on 2026/05/17 17:37

While historically I use python virtualenv helpers like 

...since virtualenv is now in the python stdlib, I have lately pared it down to two little helpers

  • mkve - makes a new basic virtualenv.
  • ve - launches a subshell with the virtualenv active - in contrast to the weird way official virtualenv activate does within the current shell session i.e ve is like vex but less fancy.
$  mkve BlahVenv
$  ve BlahVenv
$  pip install av
$  exit

mkve

#!/bin/bash
# make a new python venv:
# mkve SomeVenv

if [ -e "$1" ] ; then
   echo >&2 "Already exists. Use python -m venv ... directly for complex args."
else
   exec python -m venv "$1"
fi

ve


#!/bin/bash
# use an existing python venv in a subshell, exit to exit:
# ve SomeVenv

if [ -f "$1/bin/activate" ]; then
   exec bash --rcfile <(cat ~/.bashrc $1/bin/activate)
else
   echo >&2 "Missing Python Virtual Env (should have venv/bin/activate script)"
fi

Shell Prompt

I have a fancy non-default prompt in my .bashrc that shows a little snake if in a python virtualenv

# venvs themselves prefix these days, new ones created by stdlib honor this disable, allowing us to customize
export VIRTUAL_ENV_DISABLE_PROMPT=1
PS1='${debian_chroot:+\[\033[01;33m\]🌲($debian_chroot)\[\033[00m\]}${VIRTUAL_ENV:+\[\033[01;36m\]🐍($(basename $VIRTUAL_ENV))\[\033[00m\]}\[\033[38;5;108m\]\u@\h\[\033[38;5;128m\]:\[\033[38;5;139m\]\w\[\033[38;5;129m\]\$\[\033[00m\] '