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 from the Windows store alias paths #90

Open
tonybaloney opened this issue Jul 16, 2022 · 5 comments
Open

Python from the Windows store alias paths #90

tonybaloney opened this issue Jul 16, 2022 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@tonybaloney
Copy link

tonybaloney commented Jul 16, 2022

Not sure if this a bug in platformdirs, but users will hit this issue so I'll share my observations

Platform dirs will return the environment variable path for things like data dir, log dir for the Python from the Windows Store.

Python in the Windows store uses app execution aliases, so the actual path is something else.

For example:

>>> import platformdirs, os
>>> d = platformdirs.user_data_dir(appname="foo", appauthor="bar")
>>> os.makedirs(d)
>>> d
'C:\\Users\\anthonyshaw\\AppData\\Local\\bar\\foo\\'
>>> test_file = os.path.join(d, 'test.txt')
>>> test_file
'C:\\Users\\anthonyshaw\\AppData\\Local\\bar\\foo\\test.txt'
>>> os.path.realpath(test_file)
'C:\\Users\\anthonyshaw\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\Local\\bar\\foo\\test.txt'

This causes issues when you launch a process and use that path for something (e.g. where you created a file), but the process will resolve to a different path.

This can be disabled in apps > advanced app settings > app execution aliases in Windows.

NB: os.path.realpath only resolves this redirection in Python 3.8+ and it only works for files, not directories.

@Julian
Copy link
Member

Julian commented Jul 16, 2022

Thanks for raising -- just to confirm, the same issue exists/existed on appdirs on windows, correct?

@tonybaloney
Copy link
Author

yes, this would apply to other appdirs

@ofek
Copy link
Contributor

ofek commented Jul 17, 2022

Prior art: python-poetry/poetry#5931

@gaborbernat
Copy link
Contributor

PR welcome 👍

@gaborbernat gaborbernat added bug Something isn't working help wanted Extra attention is needed labels Nov 13, 2022
@ericoporto
Copy link

ericoporto commented Apr 8, 2023

Also found an interesting comment here

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
>>>

I am not sure how this works across python versions. I mostly really need python 3.8 compatibility as it's the last version that is compatible with Windows 7 - this also means it runs great through wine.

For my usecase, this means I prefer the "wrong" results we currently have as I don't want the redirection in Windows Store Python but want the redirection in Python over Wine, so for me, manually handling this after works best, as I believe there would be no Wine handling here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants