Skip to content

BUG: numpy.distutils fails with setuptools==65 #22135

Closed

Description

@mwittgen

Describe the issue:

The latest release of setuptools breaks builds using numpy.distutils

Reproduce the code example:

https://github.com/lsst/sphgeom/
python -m build

Error message:

Traceback (most recent call last):
        File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 261, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 404, in build_wheel
          return self._build_with_temp_dir(['bdist_wheel'], '.whl',
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 389, in _build_with_temp_dir
          self.run_setup()
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 334, in run_setup
          exec(code, locals())
        File "<string>", line 29, in <module>
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 87, in setup
          return distutils.core.setup(**attrs)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 973, in run_commands
          self.run_command(cmd)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 1217, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 992, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/wheel/bdist_wheel.py", line 299, in run
          self.run_command('build')
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 319, in run_command
          self.distribution.run_command(command)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 1217, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 992, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/command/build.py", line 132, in run
          self.run_command(cmd_name)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 319, in run_command
          self.distribution.run_command(command)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 1217, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 992, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/command/build_ext.py", line 84, in run
          _build_ext.run(self)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py", line 346, in run
          self.build_extensions()
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/pybind11/setup_helpers.py", line 288, in build_extensions
          ext.cxx_std = auto_cpp_level(self.compiler)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/pybind11/setup_helpers.py", line 267, in auto_cpp_level
          if has_flag(compiler, STD_TMPL.format(level)):
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/pybind11/setup_helpers.py", line 245, in has_flag
          compiler.compile([str(fname)], extra_postargs=[flag])
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/numpy/distutils/ccompiler.py", line 89, in <lambda>
          m = lambda self, *args, **kw: func(self, *args, **kw)
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/numpy/distutils/ccompiler.py", line 272, in CCompiler_compile
          jobs = get_num_build_jobs()
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 91, in get_num_build_jobs
          from numpy.distutils.core import get_distribution
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/numpy/distutils/core.py", line 24, in <module>
          from numpy.distutils.command import config, config_compiler, \
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/numpy/distutils/command/config.py", line 19, in <module>
          from numpy.distutils.mingw32ccompiler import generate_manifest
        File "/tmp/pip-build-env-niwad26p/overlay/lib/python3.10/site-packages/numpy/distutils/mingw32ccompiler.py", line 28, in <module>
          from distutils.msvccompiler import get_build_version as get_build_msvc_version
      ModuleNotFoundError: No module named 'distutils.msvccompiler'

NumPy/Python version information:

numpy 1.23.0 3.10.5
setuptools 65.0.0

Context for the issue:

Related to
pypa/setuptools#3505

Activity

  1. charris commented on Aug 15, 2022

    @charris
    Member

    Yes. Don't do that :) There is a reason setuptools is pinned to 59.2.0 in environment.yml, pyproject.toml, and test_requirements.txt. We will stop using setup in the future.

  2. mwittgen commented on Aug 15, 2022

    @mwittgen
    Author

    So the recommended workaround for now is to pin setuptools when using numpy.distutils?

  3. charris commented on Aug 15, 2022

    @charris
    Member

    Yes. There were supposedly some back compatibility fixes in newer setuptools, but it is a moving target and cannot be relied on.

  4. Saransh-cpp commented on Aug 16, 2022

    @Saransh-cpp
    Contributor

    Upper-capping setuptools<=64.0.0 works too!

  5. Saransh-cpp commented on Aug 17, 2022

    @Saransh-cpp
    Contributor

    FYI: This has been fixed in the new setuptools release - pypa/setuptools@v65.0.1...main (reverts back the breaking change).

  6. charris commented on Aug 17, 2022

    @charris
    Member

    IIRC, Python 3.12 will drop distutils. NumPy is looking to move to meson to solve that problem. Downstream projects are also advised to also look into alternative build systems if they currently need NumPy distutils. Things are going to be messy for a while.

  7. rgommers commented on Aug 19, 2022

    @rgommers
    Member

    Either way, our recommendation is to pin setuptools to the last version that worked for you (59.x for numpy itself, maybe 64.0 for others). This is always a good idea to do in your releases. You don't want to find out that things work at release time, and then break afterwards because setuptools or another build-time dependency did a major release.

    We already documented this at https://numpy.org/devdocs/user/depending_on_numpy.html#build-time-dependency, although we perhaps should make that a more prominent warning box. The relevant text there is: "For your other build dependencies you can probably be looser, however it’s still important to set lower and upper bounds for each dependency. It’s fine to specify either a range or a specific version for a dependency like wheel or setuptools. It’s recommended to set the upper bound of the range to the latest already released version of wheel and setuptools - this prevents future releases from breaking your packages on PyPI."

    I will open a PR to make the warning more prominent, and will advertise the recommendation here again on the mailing list.

    EDIT: note that there's a second place we recommend this, in the deprecation warning for numpy.distutils:

    warnings.warn("\n\n"
    " `numpy.distutils` is deprecated since NumPy 1.23.0, as a result\n"
    " of the deprecation of `distutils` itself. It will be removed for\n"
    " Python >= 3.12. For older Python versions it will remain present.\n"
    " It is recommended to use `setuptools < 60.0` for those Python versions.\n"
    " For more details, see:\n"
    " https://numpy.org/devdocs/reference/distutils_status_migration.html \n\n",
    DeprecationWarning, stacklevel=2
    )

  8. mattip commented on Aug 21, 2022

    @mattip
    Member

    I will open a PR to make the warning more prominent, and will advertise the recommendation here again on the mailing list.

    The PR was merged. Was the recommendation advertised on the mailing list?

  9. added a commit that references this issue on Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions