Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
quchunguang opened this issue Apr 28, 2024 · 1 comment
Open
Labels
type-bug An unexpected behavior, bug, or error

Comments

@quchunguang
Copy link

quchunguang commented Apr 28, 2024

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

@quchunguang quchunguang added the type-bug An unexpected behavior, bug, or error label Apr 28, 2024
@gaogaotiantian
Copy link
Member

I believe for the common use cases, you should not create your venv in an existing directory. So for normal usage, it won't be an issue.

Even if you are doing what you did, I think it's still valid to put the path at the front. Because

  • It won't break anything and it's not uncommon to have duplicate paths.
  • More importantly, order of paths matters. Even if the directory already exists and it's already in the path, moving up its priority still is a meaningful and useful operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants