uv: Improve message when distutil is not available on legacy python.
I use a local venv in python3.10 but compile requirements for python 3.8 (requirements used for dockerized apps) . I have both versions (along the default python 3.12) installed.
Even when I have no my 3.10 venv active uv reports the following
warning: The requested Python version 3.8 is not available. 3.10.14 will be used . But if I run python3.8 it works.
tin@morocha:~/lab/Project-API$ make dependencies
UV_CUSTOM_COMPILE_COMMAND="make dependencies" uv pip compile --python-version 3.8 --generate-hashes --output-file app/requirements/requirements-dev.txt app/requirements/requirements-dev.in
warning: The requested Python version 3.8 is not available; 3.10.14 will be used to build dependencies instead.
⠙ aiohttp==3.9.5 ^Cmake: *** [Makefile:17: app/requirements/requirements-dev.txt] Interrupción
tin@morocha:~/lab/Project-API$ python3.8
Python 3.8.19 (default, Apr 27 2024, 21:20:48)
[GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
tin@morocha:~/lab/Project-API$ which python3.8
/usr/bin/python3.8
tin@morocha:~/lab/Project-API$ python
Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
tin@morocha:~/lab/Project-API$ which python3.10
/usr/bin/python3.10
tin@morocha:~/lab/Project-API$ python3.10
Python 3.10.14 (main, Apr 27 2024, 21:17:55) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Debugging with --verbose I found the cause
DEBUG Starting interpreter discovery for Python 3.8
DEBUG Looking for exact match for request Python 3.8
DEBUG Searching for Python 3.8 in all sources
DEBUG Found CPython 3.10.14 at `/home/tin/lab/Project-API/.venv/bin/python3` (virtual environment)
DEBUG Querying Python at `/usr/bin/python3.8` failed with exit status exit status: 1
--- stdout:
--- stderr:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/tin/.cache/uv/.tmpy3nPfq/python/get_interpreter_info.py", line 555, in main
"scheme": get_scheme(),
File "/home/tin/.cache/uv/.tmpy3nPfq/python/get_interpreter_info.py", line 415, in get_scheme
return get_distutils_scheme()
File "/home/tin/.cache/uv/.tmpy3nPfq/python/get_interpreter_info.py", line 357, in get_distutils_scheme
from distutils.dist import Distribution
ModuleNotFoundError: No module named 'distutils.dist'
---
DEBUG Found CPython 3.12.3 at `/usr/bin/python3` (search path)
DEBUG Found CPython 3.12.3 at `/usr/bin/python` (search path)
DEBUG Querying Python at `/bin/python3.8` failed with exit status exit status: 1
--- stdout:
so after installing sudo apt install python3.8-distutils it works.
The error message could be clearer and indicate the exact issue, such as the missing distutils module, to help users resolve the problem more efficiently.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 19 (10 by maintainers)
Commits related to this issue
- Improve log when distutils is missing (#10713) See https://github.com/astral-sh/uv/issues/4204 for motivation This doesn't really reach the user experience I'd expect — i.e., we end up saying a virt... — committed to astral-sh/uv by zanieb 2 years ago
- Disable the distutils setuptools shim during interpreter query (#10819) Addresses https://github.com/astral-sh/uv/issues/4204#issuecomment-2604983670 Original context in https://github.com/astral-sh... — committed to astral-sh/uv by zanieb 2 years ago
Thanks @RomainBrault ! That should be resolved in #10819 — I can’t reproduce to confirm.
@KyeRussell the error message should be visible once https://github.com/astral-sh/uv/pull/10716 is merged.
I can look into adding better messaging here.
I don’t really understand why the Python distributions aren’t coming with distutils though? It was only removed from the Python standard library in 3.12, why is it missing from older Python versions here? Are the distributions stripping it from the standard library, or am I misunderstanding?
A brief Dockerfile reproduction would be helpful.
We’re working on it! #3957
Heh, OK. So, it’s a little different to what I thought / described.
When I previously isolated this, I showed the issue occurring in Ubuntu 24.04 + deadsnakes’
python3.9.This is true, but it also happens in Ubuntu 20.04 + deadsnakes’
python3.9. It didn’t affect me until now as I was unknowingly installing thepython3-distutilsUbuntu package (not a deadsnakes package) as a transient dependency of something else I had installed. In 24.04, I’m no longer installing this package. In fact, it seems to not be available for Ubuntu 24.04 at all. Ubuntu 24.04’s system Python is 3.12.So, seemingly,
python3-distutilswas available to uv / deadsnakes’ Python 3.9, which is why I never saw this earlier. Which…seems a little scary. I don’t know. I really know next to nothing about how Python is typically packaged.Anyway, I’ve created a reproduction repository here: https://github.com/KyeRussell/uv-4204-reproduction. it contains:
Working on it now 😃