pydantic 1.10.13 error on anthropic 0.26.1
Problem
Just a heads up. I am running the __Anthropic 0.26.1__ with __pydantic version 1.10.13__ and is throwing an error: _"ImportError: cannot import name 'version_short' from 'pydantic.version' (/opt/conda/lib/python3.10/site-packages/pydantic/version.cpython-310-x86_64-linux-gnu.so)"_ . The pyproject.toml asks for "pydantic>=1.9.0, <3"
Error Output
error: _"ImportError: cannot import name 'version_short' from 'pydantic.version' (/opt/conda/lib/python3.10/site-packages/pydantic/version.cpython-310-x86_64-linux-gnu.so)"_ .
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Upgrade Pydantic to Resolve ImportError with Anthropic
The error occurs because the 'version_short' attribute was removed in Pydantic version 1.10.0. Anthropic 0.26.1 likely relies on this attribute, which leads to the ImportError when using Pydantic 1.10.13. The specified version range in pyproject.toml allows for versions up to but not including 3.0, which means a compatible version of Pydantic must be used.
Awaiting Verification
Be the first to verify this fix
- 1
Check Current Pydantic Version
Verify the currently installed version of Pydantic to confirm it is causing the issue.
bashpip show pydantic - 2
Upgrade Pydantic to a Compatible Version
Upgrade Pydantic to a version that is compatible with Anthropic 0.26.1. Version 1.9.0 is the last version that supports 'version_short'.
bashpip install 'pydantic<1.10.0' - 3
Verify Anthropic Functionality
After upgrading Pydantic, test the functionality of Anthropic to ensure that the ImportError is resolved and that the application behaves as expected.
bashpython -c 'import anthropic; print(anthropic.__version__)' - 4
Update pyproject.toml
Modify the pyproject.toml file to specify the compatible version of Pydantic to prevent future issues.
bashecho 'pydantic>=1.9.0,<1.10.0' >> pyproject.toml - 5
Reinstall Dependencies
Reinstall the project dependencies to ensure that all packages are aligned with the new version constraints.
bashpip install -r requirements.txt
Validation
Run the application and check for the absence of the ImportError. Additionally, ensure that all functionalities of Anthropic are working as expected without errors.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep