Is there any way to change name, that is shown in prompt, while virtualenv activated?
username@host:~$ python3 -m venv venv
username@host:~$ source venv/bin/activate
(venv) username@host:~$
But i need it to be shown as something like this:
username@host:~$ python3 -m venv venv
username@host:~$ source venv/bin/activate
(some_arbitrary_name) username@host:~$
Originally part of the question, written by AlekseyP; removed to form a Community Wiki answer
Prompt name can not be changed after creation, however, there is a way to show some arbitrary name in prompt other than folder name:
username@host:~$ python3 -m venv .venv --prompt some_arbitrary_name
username@host:~$ source venv/bin/activate
(some_arbitrary_name) username@host:~$
The prompt is modified in the bin/activate script, so just change the line that adds (venv). It looks something like this:
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
PS1="(venv) ${PS1:-}"
export PS1
fi
Just change that (venv) to your name of choice.
Note that in more recent venv versions the above code looks like this:
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1-}"
if [ "x" != x ] ; then
PS1="() ${PS1-}"
else
PS1="(`basename \"$VIRTUAL_ENV\"`) ${PS1-}"
fi
export PS1
fi
You can still just replace
(`basename \"$VIRTUAL_ENV\"`)
with a simple string like (my_venv)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With