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 Launcher for Windows (py.exe) seems to ignore virtual environment in recent beta 3.11.0b1 #92817

Closed
Dutcho opened this issue May 15, 2022 · 3 comments · Fixed by #92988
Assignees
Labels
3.11 only security fixes OS-windows type-bug An unexpected behavior, bug, or error

Comments

@Dutcho
Copy link

Dutcho commented May 15, 2022

When typing py, I get the standard python version as set by %PY_PYTHON%, i.c. 3.10, even when a virtual environment (venv) is active.
When typing python, I get the python version from the venv, i.c. 3.11.

I expected the Python Launcher for Windows (py.exe) to prefer the CLI command argument py -<n.n> (if any) over venv over %PY_PYTHON%.
That was the way I recall py worked in 3.10. 3.11.0a7 had an issue in ignoring %PY_PYTHON%, which is now remedied in 3.11.0.b1 (thanks @zooba !). The venv part still seems to have an issue in 3.11.0b1.

Environment

(venv) >set py
PY_PYTHON=3.10

(venv) >py -0p
 -V:3.11          C:\Program Files\Python311\python.exe
 -V:3.10 *        C:\Program Files\Python310\python.exe
 -V:3.9           C:\Program Files\Python39\python.exe

Issue

(venv) >py -V -V
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]

(venv) >python -V -V
Python 3.11.0b1 (main, May  7 2022, 22:58:47) [MSC v.1931 64 bit (AMD64)]

(venv) >where python
C:\Users\[...]\venv\Scripts\python.exe
C:\Program Files\Python311\python.exe

(venv) >where py
C:\Windows\py.exe

(venv) >py -h
Python Launcher for Windows Version 3.11.0b1

usage:
py [launcher-args] [python-args] [script [script-args]]
[...]
@Dutcho Dutcho added the type-bug An unexpected behavior, bug, or error label May 15, 2022
@Dutcho
Copy link
Author

Dutcho commented May 15, 2022

(unsuccessfully looked for a way to add tags like Windows and 3.11 and 'nosy' people, like we did on the previous tracker, so hope this gets added in the process)

@AlexWaygood AlexWaygood added OS-windows 3.11 only security fixes labels May 15, 2022
@zooba
Copy link
Member

zooba commented May 16, 2022

Could well be a regression. I'll have to look at the code, but it's probably picking up the environment variable as a preference rather than a default/fallback.

@zooba zooba self-assigned this May 16, 2022
@zooba
Copy link
Member

zooba commented May 19, 2022

So how this is working is like this:

  • an active venv gets detected just like any other install (registry, app store, etc.). it gets highest priority (you should see it in "py -0p" with the venv active)
  • PY_PYTHON variable gets read if you don't specify a -x or -x.y tag and treated as if you specified it
  • the implied tag skips the venv and finds a matching version

I guess we just need an additional flag to distinguish between explicit command line arguments and implicit configuration files and environment variables (and hopefully people just know that environment variables are always implicit, even if it looks explicit in their case).

zooba added a commit to zooba/cpython that referenced this issue May 19, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 19, 2022
…H-92988)

(cherry picked from commit 73473fd)

Co-authored-by: Steve Dower <steve.dower@python.org>
miss-islington added a commit that referenced this issue May 19, 2022
(cherry picked from commit 73473fd)

Co-authored-by: Steve Dower <steve.dower@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants