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

ModuleNotFoundError: No module named 'distutils' #6509

Closed
kdheepak opened this issue Aug 23, 2024 · 4 comments
Closed

ModuleNotFoundError: No module named 'distutils' #6509

kdheepak opened this issue Aug 23, 2024 · 4 comments
Labels
great writeup A wonderful example of a quality contribution 💜 question Asking for clarification or support

Comments

@kdheepak
Copy link
Contributor

When I run uv add numpy (after adding some other dependencies successfully), I get an "No module named 'distutils'" error. I've just installed uv and ran uv install python 3.12 and tried to create a new project with it.

I'm using the following platform:

Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 12 × Apple M3 Pro
  WORD_SIZE: 64

Here's my uv --version:

$ uv --version
uv 0.3.2 (c5440001c 2024-08-23)

Here's the error I'm getting:

Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "/Users/USERNAME/.cache/uv/builds-v0/.tmpvWutaJ/lib/python3.12/site-packages/setuptools/__init__.py", line 10, in <module>
    import distutils.core
ModuleNotFoundError: No module named 'distutils'

Here's the detailed log output with uv add numpy --verbose:

https://gist.github.com/kdheepak/88fd62563e7457c0d9d17180ad907c42

Weirdly, numpy gets added to pyproject.toml:

[project]
name = "test-uv-prototype"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "jupyter>=1.0.0",
    "geopandas>=1.0.1",
    "hplot",
    "hvplot>=0.10.0",
    "numpy>=1.25.0",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
@zanieb zanieb added bug Something isn't working projects Related to project management capabilities labels Aug 23, 2024
@zanieb
Copy link
Member

zanieb commented Aug 23, 2024

Thanks for the report!

DEBUG Downloading and building requirement for build: numpy==1.26.2
DEBUG No cache entry for: https://files.pythonhosted.org/packages/2a/17/1fdc154e75d24d8c20c42b71bae1b5cf752453f0fc3a2504bbb810293dd1/numpy-1.26.2-cp312-cp312-macosx_11_0_arm64.whl
DEBUG Calling `hatchling.build.get_requires_for_build_editable()`
DEBUG Calling `setuptools.build_meta:__legacy__.get_requires_for_build_wheel()`
error: Failed to prepare distributions
  Caused by: Failed to fetch wheel: numpy==1.25.0
  Caused by: Build backend failed to determine extra requires with `build_wheel()` with exit status: 1
--- stdout:

--- stderr:
Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "/Users/USERNAME/.cache/uv/builds-v0/.tmpvWutaJ/lib/python3.12/site-packages/setuptools/__init__.py", line 10, in <module>
    import distutils.core
ModuleNotFoundError: No module named 'distutils'
---

It's failing to read numpy's metadata here. Basically the problem is that the resolver is searching for a version of numpy compatible with your other dependencies. To do this, it needs to check the requirements of each numpy version. However, it went back to a really old numpy version which requires setuptools which requires distutils which isn't provided on Python 3.12 anymore. So, in short, do uv add numpy>VERSION where VERSION is some reasonable bound on the version you're looking for. The resolver will then try more versions of other packages and either succeed, or fail with an error about why the dependencies are incompatible.

@zanieb zanieb added question Asking for clarification or support great writeup A wonderful example of a quality contribution 💜 and removed bug Something isn't working projects Related to project management capabilities labels Aug 23, 2024
@kdheepak
Copy link
Contributor Author

I don't quite understand why it picked an old version of numpy to begin with.

Also, I deleted the uv.lock file, removed numpy>=1.25.0 from the pyproject.toml (I'm not quite sure how it got in there to begin with, shouldn't the ModuleNotFoundError have prevented it from being added to pyproject.toml?) and reran uv add numpy and it added numpy 2.1.0 now and I'm no longer getting this error.

@kdheepak
Copy link
Contributor Author

I'm closing this issue because I'm no longer getting this error, but I'm not confident I know what happened here and how to reproduce it.

@kdheepak
Copy link
Contributor Author

Thanks for the swift response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
great writeup A wonderful example of a quality contribution 💜 question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

2 participants