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

No module named 'distutils' #53

Closed
kennyhei opened this issue Sep 8, 2024 · 5 comments
Closed

No module named 'distutils' #53

kennyhei opened this issue Sep 8, 2024 · 5 comments

Comments

@kennyhei
Copy link

kennyhei commented Sep 8, 2024

Got this error on macOS when I was trying to setup my project. My python version was 3.12.5. Apparently distutils has been removed in python 3.12.

Managed to fix it by adding setuptools==74.1.2 in requirements.txt and ran docker compose up --build again.

@nickjj
Copy link
Owner

nickjj commented Sep 8, 2024

Hi,

Thanks. It looks like a week ago the official Python 3.12.5 image was changed to remove this in docker-library/python#954. Prior to that it was installing that package. This project wasn't built in CI within a week.

When I build the image locally with docker compose build --no-cache I am able to reproduce the problem.

I just pushed ea3ce5c to fix it.

@nickjj nickjj closed this as completed Sep 8, 2024
@kennyhei
Copy link
Author

kennyhei commented Sep 8, 2024

Wow, that was fast! Thanks 🚀

@nickjj
Copy link
Owner

nickjj commented Sep 8, 2024

No problem, thanks to this issue I'm going to look into using GitHub Action's schedule feature to run CI every day so things like this get caught in an automated way since I'd get emailed if a build fails.

@edmorley
Copy link

edmorley commented Sep 9, 2024

I was curious whether it was a broken dependency of this project that was missing the setuptools dependency (and if so, was going to report that upstream), however, trying out a build locally I see the issue was from a first-party usage of distutils's strtobool:

worker-1    |   File "/app/src/config/settings.py", line 16, in <module>
worker-1    |     from distutils.util import strtobool
worker-1    | ModuleNotFoundError: No module named 'distutils'

Checking https://peps.python.org/pep-0632/#migration-advice it seems there isn't an official replacement for strtobool - but if you wanted to avoid having to have the entirety of setuptools as a dependency you could either:

  1. Switch to the third-party str2bool package: https://github.com/symonsoft/str2bool
  2. Vendor the strtobool function from distutils directly (since it's <10 lines): https://github.com/pypa/distutils/blob/bddd2591d35cf59b2a0d54156b195c334ab7dc8a/distutils/util.py#L329-L342

@nickjj
Copy link
Owner

nickjj commented Sep 9, 2024

Thanks, I remember thinking about this back when 3.12 dropped and I was undecided.

That str2bool package isn't backwards compatible with the one that's in distutils because it doesn't include on and off and uses a different function name. I also wasn't crazy about introducing a lib/ directory to drop in nothing more than a strtobool function so I left it be for now.

But maybe the lib/ directory idea isn't bad because it does provide an opinion on where to keep general non-project specific code that's not pulled in from a third party dependency. I already have this directory in the Flask version of this starter project.

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