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: APPDATA directory is different in store installed python
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: aku911, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-07-02 18:06 by aku911, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg372868 - (view) Author: aku911 (aku911) Date: 2020-07-02 18:08
Install the windows store python then run this code:

import os
os.listdir(os.environ['APPDATA'])

Install another version of python and run the same code.

You'll get different results.

This can cause issues when trying to share data in a user's APPDATA folder.
msg372869 - (view) Author: aku911 (aku911) Date: 2020-07-02 18:09
This is causing this issue here:
https://github.com/microsoft/vscode-python/issues/11412
msg372880 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-07-02 20:25
This is by (Windows's) design - separate apps are treated as separate by the Windows app model. In the latest and N-1 updates to Windows, the AppData redirection only applies to newly created files, not those that already exist. [1] Before then, it used copy-on-write.

The design is based on having seen many apps break because of inadvertently sharing data, and also apps failing to clean up after themselves well (of which Python is *very* guilty). The built-in "Reset App" and "Uninstall App" functions would not be viable without this separation.

What it really means for apps that are trying to share state across different Python runtimes is that they're not going to have such a great time. The best option I can offer is to use the user's Documents folder instead, which is explicitly shared (though may also be synced between machines, so not always appropriate).

The next best option is to recommend that the Store package only be used on its own, and not in conjunction with other Python installs. Those who need multiple versions or mostly-but-not-quite-separate installs will need to use the traditional installer.

But what it means for all the other tools that write to AppData is that they don't have to worry about old settings laying around or causing additional clutter. The standard "Reset app" action is a viable way to fix issues in configuration or cached files (and uninstall all packages). From a user point of view, I really like these features.

1: https://docs.microsoft.com/windows/msix/desktop/desktop-to-uwp-behind-the-scenes
msg372881 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-07-02 20:26
As an aside, virtual environments will have the same redirection as the base interpreter, so this is really only an issue between a 3.7 install and a 3.8 install, or a Store install and a traditional install.
msg372902 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-07-03 04:07
> What it really means for apps that are trying to share state across
> different Python runtimes is that they're not going to have such a 
> great time.

I tried impersonating the token of Explorer in the current thread (i.e. GetShellWindow, GetWindowThreadProcessId, OpenProcess, OpenProcessToken, ImpersonateLoggedOnUser), but writing to AppData was still redirected. Apparently redirection for apps only looks at the process token. A crude workaround is to script PowerShell or CMD in a child process.
msg372936 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-07-03 14:52
> A crude workaround is to script PowerShell or CMD in a child process.

I mean, that's not a *terrible* workaround:

>>> import os
>>> p1 = os.path.expandvars("%APPDATA%\\test.txt")
>>> p1
'C:\\Users\\steve\\AppData\\Roaming\\test.txt'
>>> open(p1, "w").close()
>>> os.system(f'copy "{os.path.realpath(p1)}" "{p1}"')
        1 file(s) copied.
0
>>>

But yeah, definitely crude :)
History
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85368
2020-07-03 14:52:12steve.dowersetmessages: + msg372936
2020-07-03 04:07:05eryksunsetnosy: + eryksun
messages: + msg372902
2020-07-02 20:26:50steve.dowersetmessages: + msg372881
2020-07-02 20:25:57steve.dowersetstatus: open -> closed
resolution: not a bug
messages: + msg372880

stage: resolved
2020-07-02 18:09:16aku911setmessages: + msg372869
2020-07-02 18:08:03aku911setmessages: + msg372868
2020-07-02 18:06:42aku911create