Skip to content

Windows pydoc.bat can use the wrong Python #3616

Description

@gaborbernat

Calling a Windows environment's Scripts\pydoc.bat by its full path can run a different Python when the environment is not activated. The resulting documentation uses that interpreter's installed packages instead of the environment's.

Affected code

pydoc.bat at ebe06113 invokes "python.exe" -m pydoc %*. BatchActivator.templates() includes that file in Windows environments.

Mechanism

The batch file gives cmd.exe an executable name without a directory. Windows command lookup checks the current directory and PATH; the batch file's own directory does not select the interpreter. Calling pydoc.bat by its path therefore leaves interpreter selection to the caller's PATH.

Reproduction

On Windows 11, with the repository at C:\src and a tox Python at C:\src\virtualenv-main-232200.tox\3.14\Scripts\python.exe, run:

Set-Location C:\src
& C:\src\virtualenv-main-232200.tox\3.14\Scripts\python.exe -m virtualenv --no-seed plainvenv
Set-Content pydoc_probe.py 'import sys; print(sys.executable)'
$env:PATH = "C:\src\virtualenv-main-232200.tox\3.14\Scripts;$env:PATH"
cmd /c 'call plainvenv\Scripts\pydoc.bat pydoc_probe'

At commit ebe06113f440731ab9c5bd6506a4793140532dc9, the imported probe printed:

C:\src\virtualenv-main-232200.tox\3.14\Scripts\python.exe

The expected interpreter is C:\src\plainvenv\Scripts\python.exe. The native check used a build of that commit, not a published wheel.

Impact

This affects Windows users who call the batch file by path without activating the environment while another Python precedes it on PATH. Reproducibility is moderate because it requires Windows and that PATH setup. Exposure is niche because it requires a direct batch-file call without activation. The observed wrong-interpreter selection is an ordinary bug.

Credits

Reported by oss-scanner: ANT-2026-76IHL4HB.

Activity

  1. added a commit that references this issue on Nov 20, 2026
    c2092dc
  2. added a commit that references this issue on Nov 20, 2026
    b8067f9
  3. added 2 commits that reference this issue on Nov 20, 2026
    3d7996c
    84fca3f
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions