镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

PowerShell venv activation treats square brackets in paths as wildcards #159498

Description

@repzakske

Bug report

PowerShell activation uses wildcard-aware path lookups for the script directory and pyvenv.cfg. Square brackets in an environment's path can prevent activation or select a similarly named sibling directory.

In an empty temporary directory, run:

python -m venv --without-pip --prompt expected 'project [2026]/.venv'
. '.\project [2026]\.venv\Scripts\Activate.ps1'

Activation reports You cannot call a method on a null-valued expression. It should activate the environment and use the configured prompt.

An existing sibling directory named venv1/Scripts can also cause the internal directory lookup for venv[1]/Scripts to select that sibling instead of the intended environment.

The relevant lookups in Lib/venv/scripts/common/Activate.ps1 use Get-Item -Path, Join-Path -Resolve -Path, and Get-Content -Path. They need to treat filesystem paths literally.

CPython versions tested on

3.15.0 and the 3.16 development branch at fdec4df45ab69fc25019565992d95b26b4e37523, with PowerShell 7.6.5 and Windows PowerShell 5.1.

Operating systems tested on

Windows.

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsstdlibStandard Library Python modules in the Lib/ directorytopic-venvRelated to the venv moduletype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions