Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the default virtualenv prompt?

How do you change the default Virtualenvwrapper prompt? By default, working on a particular virtual environment with a command like workon <_name_of_env_> prepends the name of the virtualenv to your prompt. This may work poorly if you're not using a default command prompt.

like image 200
kevin Avatar asked May 02 '12 02:05

kevin


People also ask

Is virtualenv installed by default?

Installing Virtualenv using pip3 Virtualenv is only installed on DreamHost servers for Python 2. If you're working with Python 3, you must install virtualenv using pip3. pip3 is not installed on the server by default.

What is the command to activate virtualenv?

To install virtualenv, just use pip install virtualenv . To create a virtual environment directory with it, type virtualenv /path/to/directory . Activating and deactivating the virtual environment works the same way as it does for virtual environments in Python 3 (see above).


1 Answers

If you are working on a custom PS1 (as I when found out this issue), I recommend you to disable prompt change, use export VIRTUAL_ENV_DISABLE_PROMPT=1 (see virtualenv docs), and make your own virtualenv prompt in order to add to your PS1.

See this snippet that I've used:

function virtualenv_info(){     # Get Virtual Env     if [[ -n "$VIRTUAL_ENV" ]]; then         # Strip out the path and just leave the env name         venv="${VIRTUAL_ENV##*/}"     else         # In case you don't have one activated         venv=''     fi     [[ -n "$venv" ]] && echo "(venv:$venv) " }  # disable the default virtualenv prompt change export VIRTUAL_ENV_DISABLE_PROMPT=1  VENV="\$(virtualenv_info)"; # the '...' are for irrelevant info here. export PS1="... ${VENV} ..." 
like image 152
ivanalejandro0 Avatar answered Oct 01 '22 04:10

ivanalejandro0