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

On Windows LOCALAPPDATA is missing in os.environ #3429

Closed
mminichino opened this issue Oct 29, 2024 · 8 comments
Closed

On Windows LOCALAPPDATA is missing in os.environ #3429

mminichino opened this issue Oct 29, 2024 · 8 comments

Comments

@mminichino
Copy link

Issue

This is related to #3151 - LOCALAPPDATA is needed just as APPDATA is needed. It is a commonly used Windows environment variable and it is used by popular Python packages such as python-certifi-win32.

Environment

  • OS: Windows Server 2022 Datacenter
pip list
Package              Version
-------------------- -------------
build                1.2.2.post1
CacheControl         0.14.0
cachetools           5.5.0
certifi              2024.8.30
chardet              5.2.0
charset-normalizer   3.4.0
cleo                 2.1.0
colorama             0.4.6
crashtest            0.4.1
distlib              0.3.9
dulwich              0.21.7
fastjsonschema       2.20.0
filelock             3.16.1
idna                 3.10
installer            0.7.0
jaraco.classes       3.4.0
keyring              24.3.1
more-itertools       10.5.0
msgpack              1.1.0
packaging            24.1
pexpect              4.9.0
pip                  24.2
pkginfo              1.11.2
platformdirs         4.3.6
pluggy               1.5.0
poetry               1.8.4
poetry-core          1.9.1
poetry-plugin-export 1.8.0
ptyprocess           0.7.0
pyproject-api        1.8.0
pyproject_hooks      1.2.0
pywin32-ctypes       0.2.3
RapidFuzz            3.10.1
requests             2.32.3
requests-toolbelt    1.0.0
shellingham          1.5.4
tomlkit              0.13.2
tox                  4.23.2
trove-classifiers    2024.10.21.16
urllib3              2.2.3
virtualenv           20.27.1

Output of running tox

Output of tox -rvv
ROOT: No tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at C:\Users\adminuser
py: 598 I find interpreter for spec PythonSpec(path=C:\ProgramData\scoop\apps\python312\current\python.exe) [virtualenv\discovery\builtin.py:73]
py: 598 D filesystem is not case-sensitive [virtualenv\info.py:25]
py: 605 I proposed PythonInfo(spec=CPython3.12.7.final.0-64, exe=C:\ProgramData\scoop\apps\python312\current\python.exe, platform=win32, version='3.12.7 (tags/v3.12.7:0b05ead, Oct  1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8) [virtualenv\discovery\builtin.py:80]
py: 605 D accepted PythonInfo(spec=CPython3.12.7.final.0-64, exe=C:\ProgramData\scoop\apps\python312\current\python.exe, platform=win32, version='3.12.7 (tags/v3.12.7:0b05ead, Oct  1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8) [virtualenv\discovery\builtin.py:82]
py: 610 D symlink on filesystem does not work [virtualenv\info.py:44]
py: 1383 I create virtual environment via CPython3Windows(dest=C:\Users\adminuser\.tox\py, clear=False, no_vcs_ignore=False, global=False) [virtualenv\run\session.py:50]
py: 1388 D create folder C:\Users\adminuser\.tox\py\Lib\site-packages [virtualenv\util\path\_sync.py:12]
py: 1391 D create folder C:\Users\adminuser\.tox\py\Scripts [virtualenv\util\path\_sync.py:12]
py: 1392 D write C:\Users\adminuser\.tox\py\pyvenv.cfg [virtualenv\create\pyenv_cfg.py:33]
py: 1392 D      home = C:\ProgramData\scoop\apps\python312\3.12.7 [virtualenv\create\pyenv_cfg.py:38]
py: 1392 D      implementation = CPython [virtualenv\create\pyenv_cfg.py:38]
py: 1392 D      version_info = 3.12.7.final.0 [virtualenv\create\pyenv_cfg.py:38]
py: 1392 D      virtualenv = 20.27.1 [virtualenv\create\pyenv_cfg.py:38]
py: 1392 D      include-system-site-packages = false [virtualenv\create\pyenv_cfg.py:38]
py: 1392 D      base-prefix = C:\ProgramData\scoop\apps\python312\3.12.7 [virtualenv\create\pyenv_cfg.py:38]
py: 1392 D      base-exec-prefix = C:\ProgramData\scoop\apps\python312\3.12.7 [virtualenv\create\pyenv_cfg.py:38]
py: 1392 D      base-executable = C:\ProgramData\scoop\apps\python312\3.12.7\python.exe [virtualenv\create\pyenv_cfg.py:38]
py: 1392 D copy C:\ProgramData\scoop\apps\python312\current\Lib\venv\scripts\nt\python.exe to C:\Users\adminuser\.tox\py\Scripts\python.exe [virtualenv\util\path\_sync.py:40]
py: 1399 D copy C:\ProgramData\scoop\apps\python312\current\Lib\venv\scripts\nt\pythonw.exe to C:\Users\adminuser\.tox\py\Scripts\pythonw.exe [virtualenv\util\path\_sync.py:40]
py: 1415 D create virtualenv import hook file C:\Users\adminuser\.tox\py\Lib\site-packages\_virtualenv.pth [virtualenv\create\via_global_ref\api.py:91]
py: 1415 D create C:\Users\adminuser\.tox\py\Lib\site-packages\_virtualenv.py [virtualenv\create\via_global_ref\api.py:94]
py: 1420 D ============================== target debug ============================== [virtualenv\run\session.py:52]
py: 1420 D debug via 'C:\Users\adminuser\.tox\py\Scripts\python.exe' 'C:\ProgramData\scoop\apps\python312\current\Lib\site-packages\virtualenv\create\debug.py' [virtualenv\create\creator.py:200]
py: 1420 D {
  "sys": {
    "executable": "C:\\Users\\adminuser\\.tox\\py\\Scripts\\python.exe",
    "_base_executable": "C:\\ProgramData\\scoop\\apps\\python312\\3.12.7\\python.exe",
    "prefix": "C:\\Users\\adminuser\\.tox\\py",
    "base_prefix": "C:\\ProgramData\\scoop\\apps\\python312\\3.12.7",
    "real_prefix": null,
    "exec_prefix": "C:\\Users\\adminuser\\.tox\\py",
    "base_exec_prefix": "C:\\ProgramData\\scoop\\apps\\python312\\3.12.7",
    "path": [
      "C:\\ProgramData\\scoop\\apps\\python312\\3.12.7\\python312.zip",
      "C:\\ProgramData\\scoop\\apps\\python312\\3.12.7\\DLLs",
      "C:\\ProgramData\\scoop\\apps\\python312\\3.12.7\\Lib",
      "C:\\ProgramData\\scoop\\apps\\python312\\3.12.7",
      "C:\\Users\\adminuser\\.tox\\py",
      "C:\\Users\\adminuser\\.tox\\py\\Lib\\site-packages"
    ],
    "meta_path": [
      "<class '_virtualenv._Finder'>",
      "<class '_frozen_importlib.BuiltinImporter'>",
      "<class '_frozen_importlib.FrozenImporter'>",
      "<class '_frozen_importlib_external.PathFinder'>"
    ],
    "fs_encoding": "utf-8",
    "io_encoding": "cp1252"
  },
  "version": "3.12.7 (tags/v3.12.7:0b05ead, Oct  1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)]",
  "makefile_filename": "C:\\ProgramData\\scoop\\apps\\python312\\3.12.7\\Lib\\config\\Makefile",
  "os": "<module 'os' (frozen)>",
  "site": "<module 'site' (frozen)>",
  "datetime": "<module 'datetime' from 'C:\\\\ProgramData\\\\scoop\\\\apps\\\\python312\\\\3.12.7\\\\Lib\\\\datetime.py'>",
  "math": "<module 'math' (built-in)>",
  "json": "<module 'json' from 'C:\\\\ProgramData\\\\scoop\\\\apps\\\\python312\\\\3.12.7\\\\Lib\\\\json\\\\__init__.py'>"
} [virtualenv\run\session.py:53]
py: 1549 I add seed packages via FromAppData(download=False, pip=bundle, via=copy, app_data_dir=C:\Users\adminuser\AppData\Local\pypa\virtualenv) [virtualenv\run\session.py:57]
py: 1553 D install pip from wheel C:\ProgramData\scoop\apps\python312\current\Lib\site-packages\virtualenv\seed\wheels\embed\pip-24.3.1-py3-none-any.whl via CopyPipInstall [virtualenv\seed\embed\via_app_data\via_app_data.py:49]
py: 1560 D copy directory C:\Users\adminuser\AppData\Local\pypa\virtualenv\wheel\3.12\image\1\CopyPipInstall\pip-24.3.1-py3-none-any\pip to C:\Users\adminuser\.tox\py\Lib\site-packages\pip [virtualenv\util\path\_sync.py:40]
py: 6851 D copy directory C:\Users\adminuser\AppData\Local\pypa\virtualenv\wheel\3.12\image\1\CopyPipInstall\pip-24.3.1-py3-none-any\pip-24.3.1.dist-info to C:\Users\adminuser\.tox\py\Lib\site-packages\pip-24.3.1.dist-info [virtualenv\util\path\_sync.py:40]
py: 6905 D copy C:\Users\adminuser\AppData\Local\pypa\virtualenv\wheel\3.12\image\1\CopyPipInstall\pip-24.3.1-py3-none-any\pip-24.3.1.virtualenv to C:\Users\adminuser\.tox\py\Lib\site-packages\pip-24.3.1.virtualenv [virtualenv\util\path\_sync.py:40]
py: 6912 D generated console scripts pip3.12.exe pip-3.12.exe pip3.exe pip.exe [virtualenv\seed\embed\via_app_data\pip_install\base.py:43]
py: 6912 I add activators for Bash, Batch, Fish, Nushell, PowerShell, Python [virtualenv\run\session.py:63]
py: 7019 D write C:\Users\adminuser\.tox\py\pyvenv.cfg [virtualenv\create\pyenv_cfg.py:33]
py: 7019 D      home = C:\ProgramData\scoop\apps\python312\3.12.7 [virtualenv\create\pyenv_cfg.py:38]
py: 7023 D      implementation = CPython [virtualenv\create\pyenv_cfg.py:38]
py: 7023 D      version_info = 3.12.7.final.0 [virtualenv\create\pyenv_cfg.py:38]
py: 7023 D      virtualenv = 20.27.1 [virtualenv\create\pyenv_cfg.py:38]
py: 7023 D      include-system-site-packages = false [virtualenv\create\pyenv_cfg.py:38]
py: 7023 D      base-prefix = C:\ProgramData\scoop\apps\python312\3.12.7 [virtualenv\create\pyenv_cfg.py:38]
py: 7023 D      base-exec-prefix = C:\ProgramData\scoop\apps\python312\3.12.7 [virtualenv\create\pyenv_cfg.py:38]
py: 7023 D      base-executable = C:\ProgramData\scoop\apps\python312\3.12.7\python.exe [virtualenv\create\pyenv_cfg.py:38]
  py: OK (6.45 seconds)
  congratulations :) (6.70 seconds)

Minimal example

No specific example. The LOCALAPPDATA environment variable has to be manually included via pass_env. If APPDATA is considered an automatically included variable on Windows, then LOCALAPPDATA should be included as well.

@jugmac00
Copy link
Member

The variable is not listed on https://learn.microsoft.com/en-us/windows/deployment/usmt/usmt-recognized-environment-variables.

The referenced python-certifi-win32 is unmaintained, see https://pypi.org/project/python-certifi-win32/.

While I find some mentions of LOCALAPPDATA on stackoverflow, I do not recognize a clear pattern why this should be included.

In #3151 @gaborbernat made the case that we happily include env variables that are required by the standard lib, but not app specific ones.

@mminichino
Copy link
Author

mminichino commented Oct 29, 2024 via email

@gaborbernat
Copy link
Member

My barrier of entry did not change. If it is required by a standard library method, we will add it. If it is not, even if it's a popular library from PyPI, we will not.

@gaborbernat gaborbernat closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@mminichino
Copy link
Author

mminichino commented Oct 29, 2024 via email

@mminichino
Copy link
Author

My last email reply was truncated, and one email reply seems to not have been posted.

Here is documentation from Microsoft on the Windows Win32 API that lists LOCALAPPDATA as "standard" from shellapi.h.

DoEnvironmentSubstW function

This blog post explains Windows installer target path logic including this environment variable.

@gaborbernat
Copy link
Member

Is there a method in the Python standard library that requires this environment to function correctly?

@mminichino
Copy link
Author

In my opinion you need to separate a language from the standard patterns found in operating systems where that language is commonly used. As a developer that writes software for users of an operating system, you have to follow the standard patterns found on that operating system. For POSIX based systems you can use the ubiquitous $HOME or tilde (~) to find user local paths. On Windows you have to use environment variables for software installed for either all users (APPDATA) or a single user (LOCALAPPDATA). In my humble opinion, I think you need to expand your definition of "standard" to include the target operating environment, not just Python itself.

That said, if you require a Python specific tie in, then please read Using Python on Windows from the official Python GitHub repo. It references this environment variable.

@gaborbernat
Copy link
Member

We will need to agree to disagree on this one. Also note that this doesn't stop you from using the tool, you just have to set that environmental variable in your configuration should you use a library requiring this environment variable. My definition of where I draw the line in the sand is not "mentioned in the documentation" but rather used by the Python interpreter itself or its standard library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants