conradtchan / starfit

Fit stellar abundance measurements to stellar models
Other
2 stars 0 forks source link

pip install fails with Python 3.12 #223

Open dliptai opened 4 months ago

dliptai commented 4 months ago

Installing starfit in a Python 3.12 environment results in the following error:

$ pip install --verbose starfit
Using pip 24.0 from /Users/name/mambaforge/envs/my_env/lib/python3.12/site-packages/pip (python 3.12)
Collecting starfit
  Downloading starfit-0.19.1.tar.gz (16.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 16.5/16.5 MB 6.5 MB/s eta 0:00:00
  Running command pip subprocess to install build dependencies
  Collecting setuptools>=46.1.0
    Downloading setuptools-70.3.0-py3-none-any.whl.metadata (5.8 kB)
    Downloading setuptools-65.5.1-py3-none-any.whl.metadata (6.3 kB)
  Collecting setuptools_scm>=5 (from setuptools_scm[toml]>=5)
    Downloading setuptools_scm-8.1.0-py3-none-any.whl.metadata (6.6 kB)
  Collecting numpy>=1.23.3
    Downloading numpy-2.0.0-cp312-cp312-macosx_14_0_x86_64.whl.metadata (60 kB)
       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.9/60.9 kB 1.3 MB/s eta 0:00:00
  Collecting wheel
    Downloading wheel-0.43.0-py3-none-any.whl.metadata (2.2 kB)
  Collecting packaging>=20 (from setuptools_scm>=5->setuptools_scm[toml]>=5)
    Downloading packaging-24.1-py3-none-any.whl.metadata (3.2 kB)
  Downloading setuptools-65.5.1-py3-none-any.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 6.1 MB/s eta 0:00:00
  Downloading setuptools_scm-8.1.0-py3-none-any.whl (43 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 43.7/43.7 kB 1.2 MB/s eta 0:00:00
  Downloading numpy-2.0.0-cp312-cp312-macosx_14_0_x86_64.whl (6.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.6/6.6 MB 6.5 MB/s eta 0:00:00
  Downloading wheel-0.43.0-py3-none-any.whl (65 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.8/65.8 kB 1.5 MB/s eta 0:00:00
  Downloading packaging-24.1-py3-none-any.whl (53 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.0/54.0 kB 1.4 MB/s eta 0:00:00
  Installing collected packages: wheel, setuptools, packaging, numpy, setuptools_scm
  Successfully installed numpy-2.0.0 packaging-24.1 setuptools-65.5.1 setuptools_scm-8.1.0 wheel-0.43.0
  Installing build dependencies ... done
  Running command Getting requirements to build wheel
  Traceback (most recent call last):
    File "/Users/name/mambaforge/envs/my_env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/Users/name/mambaforge/envs/my_env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Users/name/mambaforge/envs/my_env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 112, in get_requires_for_build_wheel
      backend = _build_backend()
                ^^^^^^^^^^^^^^^^
    File "/Users/name/mambaforge/envs/my_env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
      obj = import_module(mod_path)
            ^^^^^^^^^^^^^^^^^^^^^^^
    File "/Users/name/mambaforge/envs/my_env/lib/python3.12/importlib/__init__.py", line 90, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
    File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 995, in exec_module
    File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
    File "/private/var/folders/hp/b4hrd2nn7pn63znv9sjvp5gw2sck31/T/pip-build-env-xg5wehx0/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 16, in <module>
      import setuptools.version
    File "/private/var/folders/hp/b4hrd2nn7pn63znv9sjvp5gw2sck31/T/pip-build-env-xg5wehx0/overlay/lib/python3.12/site-packages/setuptools/version.py", line 1, in <module>
      import pkg_resources
    File "/private/var/folders/hp/b4hrd2nn7pn63znv9sjvp5gw2sck31/T/pip-build-env-xg5wehx0/overlay/lib/python3.12/site-packages/pkg_resources/__init__.py", line 2191, in <module>
      register_finder(pkgutil.ImpImporter, find_on_path)
                      ^^^^^^^^^^^^^^^^^^^
  AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /Users/name/mambaforge/envs/my_env/bin/python3.12 /Users/name/mambaforge/envs/my_env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py get_requires_for_build_wheel /var/folders/hp/b4hrd2nn7pn63znv9sjvp5gw2sck31/T/tmphrle5n61
  cwd: /private/var/folders/hp/b4hrd2nn7pn63znv9sjvp5gw2sck31/T/pip-install-fiwhw5u5/starfit_6478f5b14691460486839ca7ea63c84e
  Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

The issue seems to stem from the fact that pip chooses to use setuptools==65.5.1 instead of 70.3.0, see above

...
 Collecting setuptools>=46.1.0
    Downloading setuptools-70.3.0-py3-none-any.whl.metadata (5.8 kB)
    Downloading setuptools-65.5.1-py3-none-any.whl.metadata (6.3 kB)
... 

As of Python 3.12, pkgutil no longer has the class ImpImporter, which was used in setuptools.version up until setuptools<67.3.0. See https://github.com/pypa/setuptools/commit/6050634818943befefe3a85a12503b6d8a1e8106

The recommended solution is to just enforce setuptools>=67.3.0 in starfit

dliptai commented 4 months ago

The pyproject.toml that is bundled in the release tarball (both on GitHub and on PypI) is

[build-system]
# AVOID CHANGING REQUIRES: IT WILL BE UPDATED BY PYSCAFFOLD!
requires = ["setuptools>=46.1.0", "setuptools<=65.5.1", "setuptools_scm[toml]>=5", "numpy>=1.23.3", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
# See configuration details in https://github.com/pypa/setuptools_scm
version_scheme = "no-guess-dev"
fallback_version = "0.0.0"

which is why doing a pip install uses setuptools<=65.5.1

(release tarball is from 409ac15f0b8719a0ccdfcd82852138ad682c14c7)