This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Create venv with pip fails when target dir is under userappdata using Microsoft Store python
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: AdamYoblick, miss-islington, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2021-09-30 20:39 by AdamYoblick, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28663 merged steve.dower, 2021-09-30 22:18
PR 28810 merged miss-islington, 2021-10-07 20:26
PR 28811 merged miss-islington, 2021-10-07 20:26
Messages (5)
msg402983 - (view) Author: Adam Yoblick (AdamYoblick) Date: 2021-09-30 20:39
Repro steps:

1. Install Python 3.9 from the Microsoft Store
2. Try to create a virtual environment under the userappdata folder, using a command line similar to the following:

"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\python3.9.exe" -m venv "C:\Users\advolker\AppData\Local\Microsoft\CookiecutterTools\env"

3. Observe the following error:

Error: Command '['C:\\Users\\advolker\\AppData\\Local\\Microsoft\\CookiecutterTools\\env\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 106.

Note that creating a venv without pip DOES work:

"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\python3.9.exe" -m venv "C:\Users\advolker\AppData\Local\Microsoft\CookiecutterTools\env" --without-pip

BUT the venv is NOT at the specified location. This is because the Windows Store app creates a redirect when creating the venv, and that redirect is only visible from within the python executable.

This means that python doesn't respect the redirect when trying to install pip into the newly created venv.
msg402985 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-09-30 21:01
Thanks Adam.

This analysis is correct, and I think there are two parts to this.

First, we probably need to add an os.path.realpath(path_to_venv) before we try and launch the environment. We *could* limit this to when it's under AppData, but I think limiting it to Windows is enough.

Second, if the realpath generated a different path, we should warn the caller. That wouldn't have helped in this (programmatic) case, but at least if someone is looking at the output they'll get an important hint.

(The docs describing this behaviour are at https://docs.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-behind-the-scenes )
msg403442 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-10-07 20:26
New changeset 6811fdaec825bd6ab64e358a4b480108f5634d2d by Steve Dower in branch 'main':
bpo-45337: Use the realpath of the new executable when creating a venv on Windows (GH-28663)
https://github.com/python/cpython/commit/6811fdaec825bd6ab64e358a4b480108f5634d2d
msg403446 - (view) Author: miss-islington (miss-islington) Date: 2021-10-07 22:55
New changeset eabca6e593269301a0b7a36c4dc3525f04f5bb36 by Miss Islington (bot) in branch '3.10':
bpo-45337: Use the realpath of the new executable when creating a venv on Windows (GH-28663)
https://github.com/python/cpython/commit/eabca6e593269301a0b7a36c4dc3525f04f5bb36
msg403447 - (view) Author: miss-islington (miss-islington) Date: 2021-10-07 22:55
New changeset 06935bd68e3d89a4cc3f08c1d15eaa651b79a523 by Miss Islington (bot) in branch '3.9':
bpo-45337: Use the realpath of the new executable when creating a venv on Windows (GH-28663)
https://github.com/python/cpython/commit/06935bd68e3d89a4cc3f08c1d15eaa651b79a523
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89500
2021-10-07 23:24:15steve.dowersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-10-07 22:55:19miss-islingtonsetmessages: + msg403447
2021-10-07 22:55:13miss-islingtonsetmessages: + msg403446
2021-10-07 20:26:25miss-islingtonsetpull_requests: + pull_request27130
2021-10-07 20:26:22steve.dowersetmessages: + msg403442
2021-10-07 20:26:20miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request27129
2021-09-30 22:18:56steve.dowersetkeywords: + patch
stage: patch review
pull_requests: + pull_request27028
2021-09-30 21:01:55steve.dowersetmessages: + msg402985
2021-09-30 20:40:20AdamYoblicksettype: behavior
2021-09-30 20:39:58AdamYoblickcreate