Skip to content

packaging: Add Python 3.12 support - #209

Draft
caravanuden wants to merge 1 commit into
spotify:mainfrom
caravanuden:cvanuden/python-3.12-support
Draft

caravanuden wants to merge 1 commit into
spotify:mainfrom
caravanuden:cvanuden/python-3.12-support

Conversation

@caravanuden

@caravanuden caravanuden commented Nov 9, 2026 •

Copy link
Copy Markdown

Problem

pip install basic-pitch fails on Python 3.12 (fixes #159, fixes #188).
TensorFlow is pinned <2.15.1, but TensorFlow first ships Python 3.12 wheels
in 2.16. On macOS the core dependencies pull tensorflow-macos<2.15.1, which
also has no 3.12 wheels.

Solution

  • On Python >= 3.12 only, depend on tensorflow>=2.16.1 on all platforms
    (plain tensorflow has native macOS arm64 wheels; tensorflow-macos is
    discontinued), plus tf-keras and tensorboard (TensorFlow >= 2.20 no
    longer bundles TensorBoard, which visualize.py needs for
    tf.summary.audio). This applies to the core dependencies and the [tf]
    extra; markers for Python <= 3.11 are unchanged.
  • Add basic_pitch/_keras.py, which imports tf_keras when installed and
    otherwise falls back to tensorflow.keras, and route all tf.keras usages
    through it. TensorFlow >= 2.16 exposes Keras 3 as tf.keras, but the model
    and layer code targets Keras 2. I chose this over TF_USE_LEGACY_KERAS,
    which stops working whenever tensorflow is imported before basic_pitch
    and changes Keras for users' own code.
  • Pin setuptools<81 on Python >= 3.12: resampy<0.4.3 imports
    pkg_resources, which 3.12 venvs don't ship and setuptools 81 removed. The
    resampy pin itself is kept, since the test fixtures were regenerated when it
    was added (ef94d1a).
  • In tests, replace librosa.get_duration(filename=) with path=
    (filename was removed in librosa 1.0).
  • Add Python 3.12 to the classifiers, tox envlist, CI matrix
    (ubuntu/windows/macos) and README.

Result

basic-pitch installs and runs on Python 3.12; behavior on Python <= 3.11 is
unchanged.

Tested locally on macOS arm64 with Python 3.12, TensorFlow 2.21 and tf-keras
2.21:

  • pytest tests --ignore tests/data: 13 passed.
  • tests/data: local failures trace to sox/ffmpeg binaries missing on my
    machine (CI installs them), so I'm relying on CI for these and for
    Linux/Windows.
  • black: clean for the changed files. Four files on main already fail with
    current black (__init__.py, constants.py, predict.py,
    tests/data/test_medleydb_pitch.py); this PR leaves them alone.

Possible follow-ups, not in this PR: Python 3.13 support; dropping EOL Python
3.8/3.9 (and the stale 3.7 README mention); bumping actions/setup-python and
actions/checkout; relaxing the resampy<0.4.3 pin (and dropping the
setuptools pin) after regenerating fixtures.

🤖 Generated with Claude Code

TensorFlow first ships Python 3.12 wheels in 2.16, but basic-pitch pinned
tensorflow<2.15.1 (and tensorflow-macos on macOS, which has no 3.12 wheels),
so installs failed on 3.12 (spotify#159, spotify#188).

- On Python >= 3.12, depend on tensorflow>=2.16.1 (all platforms), plus
  tf-keras and tensorboard. Markers for Python <= 3.11 are unchanged.
- Add basic_pitch/_keras.py, which imports tf_keras when available and falls
  back to tensorflow.keras. TF >= 2.16 ships Keras 3 as tf.keras, while the
  model/layer code is written against Keras 2. Using a module import rather
  than TF_USE_LEGACY_KERAS works regardless of import order.
- Pin setuptools<81 on 3.12: resampy<0.4.3 imports pkg_resources.
- tests: librosa.get_duration(filename=) -> path= (filename removed in librosa 1.0).
- Add 3.12 to classifiers, tox envlist, CI matrix and README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@caravanuden caravanuden changed the title Add Python 3.12 support packaging: Add Python 3.12 support Nov 9, 2026
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

Successfully merging this pull request may close these issues.

Update to Python 3.12 to be able to use in current Colab Runtimes Issues installing basic-pitch on python3.12, any help??

1 participant