Skip to content

fix: add __version__ attribute to package#635

Open
abdelhadi703 wants to merge 1 commit intoollama:mainfrom
abdelhadi703:fix/add-version-attribute
Open

fix: add __version__ attribute to package#635
abdelhadi703 wants to merge 1 commit intoollama:mainfrom
abdelhadi703:fix/add-version-attribute

Conversation

@abdelhadi703
Copy link
Copy Markdown

Summary

The ollama package was missing a __version__ attribute, causing AttributeError: module 'ollama' has no attribute '__version__' when users try to access ollama.__version__.

Changes

  • Added __version__ attribute using importlib.metadata.version('ollama')
  • Falls back to '0.0.0' if metadata is unavailable (e.g., when running from source)
  • Added '__version__' to __all__ for proper exports

Testing

>>> import ollama
>>> ollama.__version__
'0.6.2'

Fixes #623

The ollama package was missing a __version__ attribute, causing
AttributeError when users try to access ollama.__version__.

This fix adds __version__ using importlib.metadata.version() which
reads the version from package metadata (set by hatch-vcs from git
tags). Falls back to '0.0.0' if metadata is unavailable.

Fixes ollama#623

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@Pawansingh3889 Pawansingh3889 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition — this solves a real usability gap.

One suggestion: consider catching PackageNotFoundError specifically (from importlib.metadata) rather than the broad except Exception. That way genuine unexpected errors during development still surface instead of silently falling back to 0.0.0.

Also, since __version__ is now exported via __all__, it would be worth adding a quick test for from ollama import __version__ to guard against regressions.

LGTM with the narrow exception suggestion.

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.

“缺少 __version__属性

2 participants