-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
APPDATA directory is different in store installed python #85368
Comments
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. |
This is causing this issue here: |
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 |
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. |
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. |
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 :) |
@zooba , does that work for Directories too or only files? And does this works for which python versions? |
All of this is Windows, not us. Check the document I linked earlier. It applies to everything and every version of Python depending on which version of Windows is currently running. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: