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

Corrupt .pth in site-packages #11671

Open
NilsUUID opened this issue Feb 20, 2025 · 6 comments
Open

Corrupt .pth in site-packages #11671

NilsUUID opened this issue Feb 20, 2025 · 6 comments
Labels
bug Something isn't working windows Specific to the Windows platform

Comments

@NilsUUID
Copy link

Summary

I have this pyproject.toml file defining my environement :

pyproject.toml.txt

When I run uv sync the venv gets created without problems, but if I look in /.venv/Lib/site-packages I have some .pth files that are visibly corrupt:

distutils-precedence.pth.txt

pytest-cov.pth.txt

These corrupt files cause concern afterwards when running python scripts within the environement:

C:\Users\xxx\Documents\Dev\sandbox\uv_pth_corrupt>uv run python -V
error: Querying Python at `C:\Users\xxx\Documents\Dev\sandbox\uv_pth_corrupt\.venv\Scripts\python.exe` failed with exit status exit code: 1

[stderr]
Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 980, in exec_module
  File "<frozen site>", line 626, in <module>
  File "<frozen site>", line 609, in main
  File "<frozen site>", line 541, in venv
  File "<frozen site>", line 394, in addsitepackages
  File "<frozen site>", line 236, in addsitedir
  File "<frozen site>", line 188, in addpackage
  File "C:\xxx\Python\Python3.11-64\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 41: character maps to <undefined>

As a consequence the virtual environment is unusable.

Platform

Windows 10

Version

0.6.1

Python version

3.11.9

@NilsUUID NilsUUID added the bug Something isn't working label Feb 20, 2025
@charliermarsh
Copy link
Member

I can test this when I'm back home and have my Windows machine available. Alternatively, maybe @konstin or @Gankra can test.

@charliermarsh charliermarsh added the windows Specific to the Windows platform label Feb 20, 2025
@kdheepak
Copy link
Contributor

kdheepak commented Feb 21, 2025

I was having a possibly similar / possibly related issue on a colleague's computer. On Windows, we are seeing the following error:

Error processing line 1 of C:\Users\USERNAME\miniforge3\envs\conda-env-name\lib\site-packages\distutils-precedence.pth:

  Traceback (most recent call last):
    File "C:\Users\USERNAME\miniforge3\envs\conda-env-name\lib\site-packages\...", 
  ModuleNotFoundError: No module named '_distutils_hack'

In similar issues, people recommend pip install -U setuptools pip: conda/conda#11931

But that didn't work when we tried it.

I am using the following to install a uv managed environment into a conda environment:

conda activate conda-env-name
export UV_PROJECT_ENVIRONMENT=$CONDA_PREFIX
uv sync --all-extras --dev 

I'm not sure if this is because of the same issue as the OP. I can open a new issue if this happens again. One thing to note is that I've only seen this on a Windows 11 machine.

@Gankra
Copy link
Contributor

Gankra commented Feb 21, 2025

I performed the following steps to try to reproduce on arm64 windows 11, uv 0.6.1 (unsuccessfully, everything worked fine for me):

uv init corrupt_uv_pth
<update pyproject.toml to what you have>
uv sync
<fails due to python version requirements>
uv python pin 3.11
uv sync
uv run python -V

It seems like an encoding mess but I can't tell what it would be... out of curiosity what's the windows Version in System Information? (Wondering if it's a really old win10 that lacks some system utf8 support...)

@NilsUUID
Copy link
Author

I'm running win10 22h2 on an x86-64 platform.

@Gankra
Copy link
Contributor

Gankra commented Feb 21, 2025

Thanks! That indeed should be well supported. (Which unfortunately means I'm not sure what could cause this...)

@notatallshaw
Copy link
Collaborator

I tried reproducing on Windows 10 22H2 inside a Powershell terminal window and couldn't reproduce:


PS C:\Users\damia\opensource\uv\11671> uv self update
info: Checking for updates...
success: Upgraded uv from v0.5.6 to v0.6.2! https://github.com/astral-sh/uv/releases/tag/0.6.2

PS C:\Users\damia\opensource\uv\11671> uv init corrupt_uv_pth
Initialized project `corrupt-uv-pth` at `C:\Users\damia\opensource\uv\11671\corrupt_uv_pth`

PS C:\Users\damia\opensource\uv\11671> cd .\corrupt_uv_pth\

~~ copied over pyproject.toml ~~

PS C:\Users\damia\opensource\uv\11671\corrupt_uv_pth> uv sync
Using CPython 3.10.15
error: The Python request from `.python-version` resolved to Python 3.10.15, which is incompatible with the project's Python requirement: `==3.11.*`. Use `uv python pin` to update the `.python-version` file to a compatible version.

PS C:\Users\damia\opensource\uv\11671\corrupt_uv_pth> uv python pin 3.11
warning: No interpreter found for Python 3.11 in managed installations, search path, or registry
Updated `.python-version` from `3.10` -> `3.11`

PS C:\Users\damia\opensource\uv\11671\corrupt_uv_pth> uv sync
Using CPython 3.11.11
Creating virtual environment at: .venv
Resolved 137 packages in 816ms
Prepared 134 packages in 11.05s
Installed 134 packages in 2.18s
 ~~ long list of packages ~~
 
PS C:\Users\damia\opensource\uv\11671\corrupt_uv_pth> uv run python -V
Python 3.11.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Specific to the Windows platform
Projects
None yet
Development

No branches or pull requests

5 participants