Does anybody knows how I can remove (venv) prefix that is displayed in my Powershell Terminal window? I know that this is purely cosmetic, but I'd love to remove it since I'm using Oh My Posh.
-
2I think you will have to modify your prompt function in your profile. – Olaf Aug 25 '21 at 20:15
4 Answers
I've found the best solution (for my case at least).
Simply add: $env:VIRTUAL_ENV_DISABLE_PROMPT = 1
to $PROFILE

- 183
- 1
- 6
This looks like the python environment set by conda, which modifies your prompt function when being initialized.
Search for all the possible powershell profiles in your host:
$PROFILE | Format-List -Force
Then look for the part where it says #region conda initialize
and modify it.
Alternatively you can search for the ps1
file that does this, for me it's C:\Users\Username\Miniconda3\shell\condabin\conda-hook.ps1
but ymmv.
I also use oh-my-posh, and display the environment on the right:
{
"foreground": "lightRed",
"properties": {
"display_mode": "always",
"display_version": false,
"display_virtual_env": true,
"prefix":"",
"postfix": "\uE235 "
},
"type": "python",
"style": "plain"
}

- 6,276
- 4
- 23
- 47
There is a prompt
function in your $profile
(not by default but if you have a customized prompt you will). You will have to modify it to remove the code that writes (venv)
in your prompt.

- 19,553
- 20
- 90
- 159
Go to the "C:\Program Files\Python310\Lib\venv\scripts\common" (your Python installation folder might be different)
- Find a file "Activate.ps1".
- Open the file with any editor of your choice.
- Find the line with following code (approximately line 232)
function global:prompt {
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
_OLD_VIRTUAL_PROMPT
}
Remove this variable with brackets **($_PYTHON_VENV_PROMPT_PREFIX) ** you can leave only double quotes.
After that your the function should look like this.
function global:prompt {
Write-Host -NoNewline -ForegroundColor Green ""
_OLD_VIRTUAL_PROMPT
}
- At last, recreate the environment.

- 21
- 5