python / python/cpython

`python -m venv <dir>` cause dir appairs more than one times in $PATH

Open
#118,370 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:
pwd # /home/qcg/py
python3 -m venv .
source bin/activate # or relogin the shell
import os

envs = os.environ['PATH'].split(':')
envs.sort()
print('\n'.join(envs))
#...
#/home/qcg/py/bin
#/home/qcg/py/bin
#...

my fix:
In bin/activate,

PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH

===>

case ":${PATH}:" in
    *:"$VIRTUAL_ENV/bin":*)
        ;;
    *)
        export PATH="$VIRTUAL_ENV/bin:$PATH"
        ;;
esac

Tested on Ubuntu 24.04 (in Windows WSL2) with built-in python 3.12.3.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with python3 -m venv . and source bin/activate, then inspect the generated bin/activate entry point and its PATH handling. Confirm that activating the environment does not add its bin directory more than once, including after relogging the shell.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.