fix: avoid ImportError when pinecone loads as a namespace package#656
Open
rahulsolanki001 wants to merge 1 commit intopinecone-io:mainfrom
Open
fix: avoid ImportError when pinecone loads as a namespace package#656rahulsolanki001 wants to merge 1 commit intopinecone-io:mainfrom
rahulsolanki001 wants to merge 1 commit intopinecone-io:mainfrom
Conversation
Three internal modules imported __version__ directly from the package root (`from pinecone import __version__`), which fails if `pinecone` is ever resolved as a namespace package (e.g. stale pinecone-client install, partial pip unpack, or installer edge case on Python 3.11/3.12) because namespace packages expose no attributes beyond stdlib dunders. Extract the version string into `pinecone/_version.py` and redirect all three callsites to `from pinecone._version import __version__`. Submodule imports resolve via the directory's `_NamespacePath` even when `__init__.py` is not the active package root, so the import is robust to the failure mode. `pinecone/__init__.py` is updated to re-export `__version__` from `_version.py` rather than defining it inline, keeping a single source of truth for the version string. Also adds `python-packages = ["pinecone"]` to `[tool.maturin]` so the package inclusion is explicit rather than relying on maturin's auto-discovery heuristics. Fixes: ImportError: cannot import name '__version__' from 'pinecone' (unknown location)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Python 3.11/3.12, in certain environments (stale
pinecone-clientinstall, partial pip unpack, or installer edge cases), the
pineconepackage can be resolved as a namespace package — where
pinecone.__file__ is Noneanddir(pinecone)shows only stdlib dunders.In this state, three internal callsites crash at instantiation time:
ImportError: cannot import name 'version' from 'pinecone' (unknown location)
Affected files:
pinecone/_internal/http_client.py:20pinecone/admin/admin.py:11pinecone/grpc/__init__.py:167The failure is deceptive:
import pineconeandfrom pinecone import Pineconeboth succeed, but the crash only surfaces when
Pinecone(api_key=...)isfirst called.
Fix
Extract
__version__intopinecone/_version.py(single source of truth)and redirect all three callsites to
from pinecone._version import __version__.Submodule imports resolve via
_NamespacePatheven when__init__.pyisnot the active package root, so this import is robust to the namespace
package failure mode.
pinecone/__init__.pyre-exports__version__from_version.py— nobehaviour change for normal installs.
Also adds
python-packages = ["pinecone"]to[tool.maturin]to makepackage inclusion explicit rather than relying on auto-discovery.
Files changed
pinecone/_version.py__version__ = "9.0.0"pinecone/__init__.py_versioninstead of hardcodingpinecone/_internal/http_client.pyfrom pinecone._version import __version__pinecone/admin/admin.pypinecone/grpc/__init__.pypyproject.tomlpython-packages = ["pinecone"]Note
Low Risk
Low risk: changes are limited to how
__version__is defined/imported and a packaging config tweak; runtime behavior should be unchanged except avoiding ImportError in edge-case installs.Overview
Fixes a startup crash in certain Python 3.11/3.12 edge-case installs where
pineconecan be resolved as a namespace package by moving__version__into a dedicatedpinecone/_version.pymodule.All internal callsites that used
from pinecone import __version__(HTTP client, Admin client, and gRPC client) now import__version__frompinecone._version, whilepinecone/__init__.pyre-exports it for backward compatibility. Packaging is also tightened by explicitly listingpython-packages = ["pinecone"]in thematurinconfig.Reviewed by Cursor Bugbot for commit 2347683. Bugbot is set up for automated code reviews on this repo. Configure here.