Repository navigation
Double parenthesis in activated venv generated by Python 3.12.10 #132361
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Apr 10, 2025 Please could you paste the terminal output?
This is what I get on macOS using iTerm:
/private/tmp via v3.1.3 ❯ python3.12 -m venv venv source venv/bin/activate /private/tmp via v3.12.10 (venv) via v3.1.3 took 10s ❯ python3.12 --version Python 3.12.10 /private/tmp via v3.12.10 (venv) via v3.1.3
I encountered this too.
[srv1] [2025-04-10 22:27:08] zsh [~] $ lsb_release -d No LSB modules are available. Description: Ubuntu 24.04.2 LTS [srv1] [2025-04-10 22:27:26] zsh [~] $ pyenv global 3.12.10 [srv1] [2025-04-10 22:27:27] zsh [~] $ which python /home/i9wa4/.pyenv/shims/python [srv1] [2025-04-10 22:27:35] zsh [~] $ python --version Python 3.12.10 [srv1] [2025-04-10 22:27:58] zsh [~] $ python -m venv venv3.12.10 [srv1] [2025-04-10 22:28:11] zsh [~] $ source venv3.12.10/bin/activate ((venv3.12.10) ) [srv1] [2025-04-10 22:28:11] zsh [~] $
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-venvRelated to the venv moduleRelated to the venv module
on Apr 10, 2025 I can reproduce this. I think this may be related to this diff, which was included in the 3.12 backport, but not in the main PR
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then _OLD_VIRTUAL_PS1="${PS1:-}" - PS1=__VENV_PROMPT__"${PS1:-}" + PS1="("__VENV_PROMPT__") ${PS1:-}" export PS1 - VIRTUAL_ENV_PROMPT=__VENV_PROMPT__ - export VIRTUAL_ENV_PROMPT fiFor context, the generated
activatescript looks like this:# [...] VIRTUAL_ENV_PROMPT='(venv) ' export VIRTUAL_ENV_PROMPT # unset PYTHONHOME if set # this will fail if PYTHONHOME is set to the empty string (which is bad anyway) # could use `if (set -u; : $PYTHONHOME) ;` in bash if [ -n "${PYTHONHOME:-}" ] ; then _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" unset PYTHONHOME fi if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then _OLD_VIRTUAL_PS1="${PS1:-}" PS1="("'(venv) '") ${PS1:-}" export PS1 fi # [...]
cc @vsajip
Reacted by DenisKThis issue should be closed, it only affects 3.12 which no longer allows bugfixes.
Reacted by Hugo van Kemenade and kushal-kumar-aReproducible in 3.12:
❯ docker run --rm -it python:3.12 bash root@9131fb969a1b:/# python3 --version Python 3.12.10 root@9131fb969a1b:/# python -m venv venv root@9131fb969a1b:/# source venv/bin/activate ((venv) ) root@9131fb969a1b:/# exit
But not 3.13:
❯ docker run --rm -it python:3.13 bash root@05795675a6a3:/# python3 --version Python 3.13.3 root@05795675a6a3:/# python -m venv venv root@05795675a6a3:/# source venv/bin/activate (venv) root@05795675a6a3:/# exit
Reacted by Stan Ulbrych and aditya thomasVery unfortunate, introduced just days before the deadline, and very visible too :-(
Reacted by Daiki Mawatari | uma-chan, Nathan Chappell, aditya thomas, DS/Charlie, Carter Jameson, Arman Rezaei and Yushi YangAll the more reason to upgrade to Python 3.13, and get all the other bugfixes too 👍
Reacted by Stan Ulbrych and kushal-kumar-aCame here pretty late. Is this only a cosmetic bug or does it have any consequences?
Likely only cosmetic.
- marked [3.12.11] virtual env shell (ps1) prompt double parentheses around name #135979 as a duplicate of this issue
on Jun 26, 2025 In case anyone wants to fix it themselves in a fork, here's what I think is going on:
The venv activate script generated by Python includes a redundant wrapping of parentheses and a trailing space in the PS1 prompt assignment.
In current versions (3.11, 3.12, not sure about 3.13), eg when creating a ~/venv312 environment:
the generated activate script includes the following:
VIRTUAL_ENV_PROMPT='(venv312) ' # note parens & trailing space.
...
Line 57
PS1="("VENV_PROMPT") ${PS1:-}" # note additional parens & interval spaceThis results in a prompt like: "((venv312) ) usersprompt$" prompt with double parentheses and an extra trailing space.
apparently because the script adds more parens & spaces in line 70:
https://github.com/python/cpython/blob/main/Lib/venv/scripts/common/activate
line 57
VIRTUAL_ENV_PROMPT=VENV_PROMPT
...
line 70
PS1="("VENV_PROMPT") ${PS1:-}" # Note added parens & trailing space around VENV_PROMPTSuggested Fix:
Suggest use either inject the environment name itself (e.g., venv312) into the prompt string,
and use only the shell script to format it, or if necessary (less optimal)
Use the VENV_ENV_PROMPT as is without adding additional parens & spaces#https://github.com/python/cpython/blob/main/Lib/venv/scripts/common/activate
line 57
VIRTUAL_ENV_PROMPT="(VENV_NAME)" #use only venv name, not a preformatted prompt
...
line 70
PS1="${VIRTUAL_ENV_PROMPT} ${PS1:-}" #remove extra parens & space here if unable to use VENV_NAMEThis avoids duplication and makes the script easier to read, maintain or override.
The change should apply to:
Lib/venv/scripts/common/activateMay also need to remove formatting from template injection code here:
https://github.com/python/cpython/blob/main/Lib/venv/__init__.py (whereline 483 def replace_variables(self, text, context):
line 496 'VENV_NAME': context.env_name,
line 497 'VENV_PROMPT': context.prompt,I can confirm that 3.13.5 at least has fixed this bug. It's such a simple but annoying one it's too bad it won't be backported to 3.11 & 3.12. There was some mention in the 'blame' section about quotes for avoiding injection so perhaps there is a security risk?
Just a +1 to say this is what I'd call out-of-character for Python at this point in its life? Introducing a bug into the last bugfix release of a version is disappointing. To compliment sandwich it, I suppose it says a lot that Python has gotten to the maturity where we can expect that things like this won't happen. But then they do happen. I can see that this won't get fixed, but with 3.13 being effectively a major version bump (due to cython major version incompatibility) and needing long runway, this—admittedly cosmetic—unfixable bug isn't up to the standard of professionalism I've come to expect from the hardworking maintainers of Python. Keep working hard, and know that I still believe in you all now more than I ever did before!
Reacted by Tommy JenkinsWe don't use SemVer and every Python feature release is effectively a "major" bump due to removed deprecations.
If you'd like to help out, we have 2k open PRs that can benefit from review. Also the last ever 3.9 release is going out any day now before its EOL, so you're welcome to double check already merged PRs to that branch.
Bug report
Bug description:
python3.12 -m venv venv source venv/bin/activateThere will be double parenthesis displayed on the terminal. This bug may be related to this commit because Python 3.12.9 is normal.
CPython versions tested on:
3.12
Operating systems tested on:
Linux