simonw / llm-claude-3

LLM plugin for interacting with the Claude 3 family of models
Apache License 2.0
254 stars 23 forks source link

Installation fails due to PyO3 dependency - incompatible with Python 3.13 #16

Closed mfasold closed 2 weeks ago

mfasold commented 1 month ago

I just did a fresh installation of llm via brew on a M1 Mac, followed by llm install llm-claude-3.

Here, I get the following error

Building wheels for collected packages: tokenizers
  Building wheel for tokenizers (pyproject.toml) ... error
...
      error: failed to run custom build command for `pyo3-ffi v0.21.2`

      Caused by:
        process didn't exit successfully: `/private/var/folders/sk/kx1k0x6522j0g4y_5h137d4w0000gn/T/pip-install-ev5faqat/tokenizers_22eea7ad05ff47b9b1d00ab3bf8670bb/bindings/python/target/release/build/pyo3-ffi-6e049bc9fd234003/build-script-build` (exit status: 1)
        --- stdout
        cargo:rerun-if-env-changed=PYO3_CROSS
        cargo:rerun-if-env-changed=PYO3_CROSS_LIB_DIR
        cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_VERSION
        cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_IMPLEMENTATION
        cargo:rerun-if-env-changed=PYO3_PRINT_CONFIG
        cargo:rerun-if-env-changed=PYO3_USE_ABI3_FORWARD_COMPATIBILITY

        --- stderr
        error: the configured Python interpreter version (3.13) is newer than PyO3's maximum supported version (3.12)
        = help: please check if an updated version of PyO3 is available. Current version: 0.21.2
        = help: set PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 to suppress this check and build anyway using the stable ABI
      warning: build failed, waiting for other jobs to finish...
      💥 maturin failed
        Caused by: Failed to build a native library through cargo
        Caused by: Cargo build finished with "exit status: 101": `env -u CARGO MACOSX_DEPLOYMENT_TARGET="11.0" PYO3_ENVIRONMENT_SIGNATURE="cpython-3.13-64bit" PYO3_PYTHON="/opt/homebrew/Cellar/llm/0.16/libexec/bin/python" PYTHON_SYS_EXECUTABLE="/opt/homebrew/Cellar/llm/0.16/libexec/bin/python" "cargo" "rustc" "--features" "pyo3/extension-module" "--message-format" "json-render-diagnostics" "--manifest-path" "/private/var/folders/sk/kx1k0x6522j0g4y_5h137d4w0000gn/T/pip-install-ev5faqat/tokenizers_22eea7ad05ff47b9b1d00ab3bf8670bb/bindings/python/Cargo.toml" "--release" "--lib" "--" "-C" "link-arg=-undefined" "-C" "link-arg=dynamic_lookup" "-C" "link-args=-Wl,-install_name,@rpath/tokenizers.tokenizers.cpython-313-darwin.so"`
      Error: command ['maturin', 'pep517', 'build-wheel', '-i', '/opt/homebrew/Cellar/llm/0.16/libexec/bin/python', '--compatibility', 'off'] returned non-zero exit status 1
      [end of output]

Any ideas on that? Was there maybe a recent update to python@3.13? The suggested workaround PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 also did not work out.

ddgond commented 1 month ago

Also encountering this issue, including when uninstalling from brew and reinstalling via pipx. From what I can tell online, version 0.22 of PyO3 fixes it, but I'm not sure where that version gets specified.

schpet commented 4 weeks ago

also running into this with homebrew and pipx.

workaround i'm using is to use llm via uvx

uvx --python 3.12 llm install llm-claude-3

# for some reason ANTHROPIC_API_KEY wasn't being picked up
uvx --python 3.12 llm keys set claude --value "$ANTHROPIC_API_KEY"

i saved this as an alias in fish:

alias --save llm "uvx --python 3.12 llm"
chetstone commented 3 weeks ago

I just had a long chat with Claude about this. The problem is that a new install of llm will pull in python3.13 as a dependency and Pyo3 has not been upgraded yet. The workaround is to revert to python@3.12:

brew uninstall llm
brew install python@3.12
pipx install --python /opt/homebrew/bin/python3.12 llm
llm install llm-claude-3
simonw commented 3 weeks ago

I just hit this one too, in CI: https://github.com/simonw/llm-claude-3/actions/runs/11565609702/job/32192886633

  Created wheel for llm-claude-3: filename=llm_claude_3-0.6a0-0.editable-py3-none-any.whl size=7960 sha256=007b7775d41cba4b38f132561923f0ecabd9db7c73a2fbe81a780399f422a97d
  Stored in directory: /tmp/pip-ephem-wheel-cache-4evjc8fh/wheels/f1/ac/be/2de1191119d760a7eea714608024373fe4de08f27f8ae9d6bf
  Building wheel for tokenizers (pyproject.toml): started
  Building wheel for tokenizers (pyproject.toml): finished with status 'error'
  error: subprocess-exited-with-error

  × Building wheel for tokenizers (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [65 lines of output]
      Running `maturin pep517 build-wheel -i /opt/hostedtoolcache/Python/3.13.0/x64/bin/python --compatibility off`
      🍹 Building a mixed python/rust project
      🔗 Found pyo3 bindings
      🐍 Found CPython 3.13 at /opt/hostedtoolcache/Python/3.13.0/x64/bin/python
      📡 Using build options features, bindings from pyproject.toml
         Compiling proc-macro2 v1.0.86
         Compiling unicode-ident v1.0.13
         Compiling autocfg v1.4.0
         Compiling libc v0.2.159
         Compiling target-lexicon v0.12.16
         Compiling once_cell v1.20.1
         Compiling memchr v2.7.4
         Compiling pyo3-build-config v0.21.2
         Compiling cfg-if v1.0.0
         Compiling shlex v1.3.0
         Compiling cc v1.1.22
         Compiling quote v1.0.37
         Compiling syn v2.0.79
         Compiling crossbeam-utils v0.8.20
         Compiling ident_case v1.0.1
         Compiling strsim v0.11.1
         Compiling fnv v1.0.7
         Compiling num-traits v0.2.19
         Compiling portable-atomic v1.9.0
         Compiling smallvec v1.13.2
         Compiling serde v1.0.210
         Compiling crossbeam-epoch v0.9.18
         Compiling pyo3-ffi v0.21.2
         Compiling aho-corasick v1.1.3
         Compiling lock_api v0.4.12
         Compiling regex-syntax v0.8.5
         Compiling parking_lot_core v0.9.10
         Compiling rayon-core v1.12.1
         Compiling byteorder v1.5.0
         Compiling pkg-config v0.3.31
         Compiling either v1.13.0
         Compiling darling_core v0.20.10
         Compiling zerocopy-derive v0.7.35
         Compiling darling_macro v0.20.10
         Compiling serde_derive v1.0.210
         Compiling darling v0.20.10
         Compiling zerocopy v0.7.35
         Compiling regex-automata v0.4.8
         Compiling onig_sys v69.8.1
      error: failed to run custom build command for `pyo3-ffi v0.21.2`

      Caused by:
        process didn't exit successfully: `/tmp/pip-install-8o1e7nh7/tokenizers_34e46dfe9fae47c086d9b2bec3a18f42/bindings/python/target/release/build/pyo3-ffi-f520a0951f03389d/build-script-build` (exit status: 1)
        --- stdout
        cargo:rerun-if-env-changed=PYO3_CROSS
        cargo:rerun-if-env-changed=PYO3_CROSS_LIB_DIR
        cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_VERSION
        cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_IMPLEMENTATION
        cargo:rerun-if-env-changed=PYO3_PRINT_CONFIG
        cargo:rerun-if-env-changed=PYO3_USE_ABI3_FORWARD_COMPATIBILITY

        --- stderr
        error: the configured Python interpreter version (3.13) is newer than PyO3's maximum supported version (3.12)
        = help: please check if an updated version of PyO3 is available. Current version: 0.21.2
        = help: set PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 to suppress this check and build anyway using the stable ABI
      warning: build failed, waiting for other jobs to finish...
      💥 maturin failed
        Caused by: Failed to build a native library through cargo
        Caused by: Cargo build finished with "exit status: 101": `env -u CARGO PYO3_ENVIRONMENT_SIGNATURE="cpython-3.13-64bit" PYO3_PYTHON="/opt/hostedtoolcache/Python/3.13.0/x64/bin/python" PYTHON_SYS_EXECUTABLE="/opt/hostedtoolcache/Python/3.13.0/x64/bin/python" "cargo" "rustc" "--features" "pyo3/extension-module" "--message-format" "json-render-diagnostics" "--manifest-path" "/tmp/pip-install-8o1e7nh7/tokenizers_34e46dfe9fae47c086d9b2bec3a18f42/bindings/python/Cargo.toml" "--release" "--lib"`
      Error: command ['maturin', 'pep517', 'build-wheel', '-i', '/opt/hostedtoolcache/Python/3.13.0/x64/bin/python', '--compatibility', 'off'] returned non-zero exit status 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for tokenizers
Successfully built llm-claude-3
Failed to build tokenizers
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (tokenizers)
simonw commented 3 weeks ago

Here's the issue for the PyO3 Python 3.13 compatibility:

And this PR tracking what needs to be done, which says it's aiming for a November 1st release at the moment:

simonw commented 3 weeks ago

Filed an issue against anthropic here:

Since the PyO3 fix is due within a week I'm going to leave this for the moment.

simonw commented 3 weeks ago

I opened a PR against the Anthropic client library here:

simonw commented 3 weeks ago

Here's a workaround using my Anthropic client library branch. First install my branch that works in Python 3.13:

llm install https://github.com/simonw/anthropic-sdk-python/archive/9c13bb441ee4eb88a100ed363fc431ec8fd30c43.zip

Now this should work:

llm install llm-claude-3
ryantuck commented 2 weeks ago

Docker is a handy tool for working around odd environment install issues, and is what I reached for to work around this particular problem. I don't see anything docker-specific in the issues, so posting my solution here in case it helps anyone else :)

Dockerfile:

FROM python:3.12

RUN pip install llm
RUN llm install llm-claude-3

ENTRYPOINT ["llm"]

I created a basic alias in ~/.zshrc to pass in the API key and haiku as the model since that was already the default I was rolling with:

alias llm="docker run -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY llm-docker --model claude-3-haiku"

Also just wanted to say thanks for making a very nice CLI for this, I use it all the time.