readthedocs.org: ModuleNotFoundError: No module named 'setuptools._distutils'

Hi,

We use readthedocs for the jarvis-tools package. Recently, I am seeing an error due to setuptools:

Raw log here: https://readthedocs.org/api/v2/build/15584283.txt

I am wondering if somebody can help me with this.


šŸ“Œ Edit by @astrojuanlu šŸ“Œ This issue is triggered by setuptools 60, released on 2021-12-19. Current status:

  • ~If your project doesn’t have a pyproject.toml, most likely you have the ā€œuse system packagesā€ version enabled. You can (1) disable it, (2) cap setuptools yourself in your requirements, or (3) wait for us to deploy a fix (January 2022) . See below for more context.~ Update: This has been fixed on RTD as of Dec 21.
  • If your project does have a pyproject.toml, most likely pip is using its fallback mode and installing the problematic setuptools version in an isolated environment. In this case, there is nothing Read the Docs can do to fix your problem. You can do it yourself by adding a proper [build-system] PEP 518 table to your pyproject.toml file. See below for more information.
  • You can temporarily roll back to the old setuptools behavior by exporting a SETUPTOOLS_USE_DISTUTILS=stdlib environment variable for your project. However, it is not guaranteed that this will work forever, and we encourage you to look into the solution above.
  • If you were redirected here, it’s because you opened a new issue for this exact problem. Please try the solution above first.
  • If it didn’t work, leave a comment below with a link to your failing build.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 23 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@uvchik I think your case is slightly different. Since your project has a pyproject.toml file, pip triggers a different install mode that performs build isolation:

For building packages using this interface, pip uses an isolated environment. That is, pip will install build-time Python dependencies in a temporary directory which will be added to sys.path for the build commands.

Then, since your pyproject.toml does not define build-time dependencies as per PEP 518, pip uses a fallback mode. Therefore, no matter what setuptools version you install in your requirements.txt, and no matter what version we magically install for you, pip will use the newest version that fits the "setuptools>=40.8.0" pinning. In your case, the problematic setuptools 60.x.

The solution in your case is to add the following contents to your pyproject.toml:

[build-system]
requires = ["setuptools<60.0", "wheel"]
build-backend = "setuptools.build_meta"

Can you please try it and let us know if it works?

Leaving this issue pinned so folks can easily find it, but we have done our part from the RTD side already to avoid that most projects experience it, so I am closing it. Feel free to continue the conversation here, but remember to read the current status in the first comment before doing so.

Thank you. Works fine.

Added detailed instructions with several methods to fix this issue in the first comment ā˜šŸ½

We were using the system packages because we depend on Matplotlib, scipy, numpy, etc. and wanted to avoid installing them from scratch. But turning off system packages seems to have fixed the issue.

I checked and we had the ā€œuse system packagesā€ option enabled as well, I don’t recall why. I unchecked it and re-ran the builds and they passed. So that fixed it for us. Thank you!

Oh, of course I understand why. We’re passing --upgrade in the second pip install command, so the pip install setuptools<58.3.0 is useless. This will need a fix.