hatch
hatch copied to clipboard
hatch shell fails to create env
I am running Ubuntu 20.04 with Python 3.8.10 in Windows WSL and am getting this error when running hatch shell:
$ hatch --version
Hatch, version 1.12.0
$ hatch shell
Creating environment: default
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/hatch/cli/__init__.py:221 in main │
│ │
│ 218 │
│ 219 def main(): # no cov │
│ 220 │ try: │
│ ❱ 221 │ │ hatch(prog_name='hatch', windows_expand_args=False) │
│ 222 │ except Exception: # noqa: BLE001 │
│ 223 │ │ import sys │
│ 224 │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/click/core.py:1157 in __call__ │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/click/core.py:1078 in main │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/click/core.py:1688 in invoke │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/click/core.py:1434 in invoke │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/click/core.py:783 in invoke │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/click/decorators.py:45 in new_func │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/hatch/cli/shell/__init__.py:45 in │
│ shell │
│ │
│ 42 │ │
│ 43 │ with app.project.ensure_cwd(): │
│ 44 │ │ environment = app.get_environment(chosen_env) │
│ ❱ 45 │ │ app.prepare_environment(environment) │
│ 46 │ │ │
│ 47 │ │ first_run_indicator = app.cache_dir / 'shell' / 'first_run' │
│ 48 │ │ if not first_run_indicator.is_file(): │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/hatch/cli/application.py:111 in │
│ prepare_environment │
│ │
│ 108 │ │ │ self.env_metadata.reset(environment) │
│ 109 │ │ │ │
│ 110 │ │ │ with environment.app_status_creation(): │
│ ❱ 111 │ │ │ │ environment.create() │
│ 112 │ │ │ │
│ 113 │ │ │ if not environment.skip_install: │
│ 114 │ │ │ │ if environment.pre_install_commands: │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/hatch/env/virtual.py:158 in create │
│ │
│ 155 │ │ │ │ ) │
│ 156 │ │ │
│ 157 │ │ with self.expose_uv(): │
│ ❱ 158 │ │ │ self.virtual_env.create(self.parent_python, allow_system_packages=self.confi │
│ 159 │ │
│ 160 │ def remove(self): │
│ 161 │ │ self.virtual_env.remove() │
│ │
│ /usr/lib/python3.8/functools.py:967 in __get__ │
│ │
│ 964 │ │ │ │ # check if another thread filled cache while we awaited lock │
│ 965 │ │ │ │ val = cache.get(self.attrname, _NOT_FOUND) │
│ 966 │ │ │ │ if val is _NOT_FOUND: │
│ ❱ 967 │ │ │ │ │ val = self.func(instance) │
│ 968 │ │ │ │ │ try: │
│ 969 │ │ │ │ │ │ cache[self.attrname] = val │
│ 970 │ │ │ │ │ except TypeError: │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/hatch/env/virtual.py:278 in │
│ parent_python │
│ │
│ 275 │ │ if explicit_default := os.environ.get(AppEnvVars.PYTHON): │
│ 276 │ │ │ return sys.executable if explicit_default == 'self' else explicit_default │
│ 277 │ │ │
│ ❱ 278 │ │ return self._get_concrete_interpreter_path() │
│ 279 │ │
│ 280 │ @cached_property │
│ 281 │ def python_manager(self) -> PythonManager: │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/hatch/env/virtual.py:327 in │
│ _get_concrete_interpreter_path │
│ │
│ 324 │ │ else: │
│ 325 │ │ │ # Prefer the Python version Hatch is currently using │
│ 326 │ │ │ for resolver in resolvers: │
│ ❱ 327 │ │ │ │ if (concrete_path := resolver(self._preferred_python_version)) is not No │
│ 328 │ │ │ │ │ return concrete_path │
│ 329 │ │ │ │
│ 330 │ │ │ # Fallback to whatever is compatible │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/hatch/env/virtual.py:338 in │
│ _resolve_external_interpreter_path │
│ │
│ 335 │ │ return None │
│ 336 │ │
│ 337 │ def _resolve_external_interpreter_path(self, python_version: str) -> str | None: │
│ ❱ 338 │ │ if (existing_path := self._find_existing_interpreter(python_version)) is not Non │
│ 339 │ │ │ self.upgrade_possible_internal_python(existing_path) │
│ 340 │ │ │ return existing_path │
│ 341 │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/hatch/env/virtual.py:367 in │
│ _find_existing_interpreter │
│ │
│ 364 │ │ │
│ 365 │ │ virtualenv_discovery.propose_interpreters = _patched_propose_interpreters │
│ 366 │ │ try: │
│ ❱ 367 │ │ │ python_info = virtualenv_discovery.get_interpreter( │
│ 368 │ │ │ │ python_version, (), env=self.get_interpreter_resolver_env() │
│ 369 │ │ │ ) │
│ 370 │ │ │ if python_info is not None: │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/virtualenv/discovery/builtin.py:75 │
│ in get_interpreter │
│ │
│ 72 │ logging.info("find interpreter for spec %r", spec) │
│ 73 │ proposed_paths = set() │
│ 74 │ env = os.environ if env is None else env │
│ ❱ 75 │ for interpreter, impl_must_match in propose_interpreters(spec, try_first_with, app_d │
│ 76 │ │ key = interpreter.system_executable, impl_must_match │
│ 77 │ │ if key in proposed_paths: │
│ 78 │ │ │ continue │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/hatch/env/virtual.py:359 in │
│ _patched_propose_interpreters │
│ │
│ 356 │ │ propose_interpreters = virtualenv_discovery.propose_interpreters │
│ 357 │ │ │
│ 358 │ │ def _patched_propose_interpreters(*args, **kwargs): │
│ ❱ 359 │ │ │ for interpreter, impl_must_match in propose_interpreters(*args, **kwargs): │
│ 360 │ │ │ │ if not self._interpreter_is_compatible(interpreter): │
│ 361 │ │ │ │ │ continue │
│ 362 │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/virtualenv/discovery/builtin.py:147 │
│ in propose_interpreters │
│ │
│ 144 │ │ │ │ yield interpreter, True │
│ 145 │ # finally just find on path, the path order matters (as the candidates are less easy │
│ 146 │ find_candidates = path_exe_finder(spec) │
│ ❱ 147 │ for pos, path in enumerate(get_paths(env)): │
│ 148 │ │ logging.debug(LazyPathDump(pos, path, env)) │
│ 149 │ │ for exe, impl_must_match in find_candidates(path): │
│ 150 │ │ │ exe_raw = str(exe) │
│ │
│ /home/nn/.local/pipx/venvs/hatch/lib/python3.8/site-packages/virtualenv/discovery/builtin.py:170 │
│ in get_paths │
│ │
│ 167 │ if not path: │
│ 168 │ │ return None │
│ 169 │ for p in map(Path, path.split(os.pathsep)): │
│ ❱ 170 │ │ if p.exists(): │
│ 171 │ │ │ yield p │
│ 172 │
│ 173 │
│ │
│ /usr/lib/python3.8/pathlib.py:1407 in exists │
│ │
│ 1404 │ │ Whether this path exists. │
│ 1405 │ │ """ │
│ 1406 │ │ try: │
│ ❱ 1407 │ │ │ self.stat() │
│ 1408 │ │ except OSError as e: │
│ 1409 │ │ │ if not _ignore_error(e): │
│ 1410 │ │ │ │ raise │
│ │
│ /usr/lib/python3.8/pathlib.py:1198 in stat │
│ │
│ 1195 │ │ Return the result of the stat() system call on this path, like │
│ 1196 │ │ os.stat() does. │
│ 1197 │ │ """ │
│ ❱ 1198 │ │ return self._accessor.stat(self) │
│ 1199 │ │
│ 1200 │ def owner(self): │
│ 1201 │ │ """ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
PermissionError: [Errno 13] Permission denied: '/mnt/c/WINDOWS/system32/config/systemprofile/AppData/Local/Microsoft/WindowsApps'
PS. Unrelated -- I believe there should be an environment variable to avoid having the traceback being "nicely" formatted, I hope this is good enough for reading on Github.
A workaround seems to be to upgrade Python version that Hatch uses.
$ pipx uninstall hatch
uninstalled hatch! ✨ 🌟 ✨
$ pipx install --python python3.10 hatch
installed package hatch 1.12.0, installed using Python 3.10.13
These apps are now globally available
- hatch
$ hatch shell
[...successfully create and activate the venv...]
$ echo $?
0