pandas-dev/pandas · error · ImportError
Can't determine version for {module.__name__}
Error message
Can't determine version for {module.__name__} What it means
Raised by get_version (compat/_optional.py:76-84) when an imported module has no __version__ attribute. pandas uses this to compare dependency versions against required minimums (VERSIONS dict). If the module loaded but its package didn't expose __version__, pandas cannot verify the minimum and raises ImportError. Note: psycopg2 is special-cased (its version string is split).
Source
Thrown at pandas/compat/_optional.py:80
# these two names are different.
INSTALL_MAPPING = {
"bs4": "beautifulsoup4",
"bottleneck": "Bottleneck",
"jinja2": "Jinja2",
"lxml.etree": "lxml",
"odf": "odfpy",
"python_calamine": "python-calamine",
"sqlalchemy": "SQLAlchemy",
"tables": "pytables",
}
def get_version(module: types.ModuleType) -> str:
version = getattr(module, "__version__", None)
if version is None:
raise ImportError(f"Can't determine version for {module.__name__}")
if module.__name__ == "psycopg2":
# psycopg2 appends " (dt dec pq3 ext lo64)" to its version
version = version.split()[0]
return version
@overload
def import_optional_dependency(
name: str,
extra: str = ...,
min_version: str | None = ...,
*,
errors: Literal["raise"] = ...,
) -> types.ModuleType: ...
@overload
def import_optional_dependency(View on GitHub (pinned to 71959b8cb9)
Solutions
- Ensure the real, packaged version of the dependency is installed (pip install --force-reinstall <pkg>).
- Check for a local file/module shadowing the package: import <pkg>; print(<pkg>.__file__).
- If you control the dependency, add __version__ to its package __init__.
- If you must use a version-less module, call import_optional_dependency with errors='ignore' (you lose version gating).
Example fix
# before — local 'tables.py' shadows pytables, no __version__
import_optional_dependency('tables', min_version='3.0')
# after
pip install --force-reinstall tables # or rename/remove the shadowing file Defensive patterns
Strategy: validation
Validate before calling
import importlib
mod = importlib.import_module(name)
if not hasattr(mod, '__version__'):
raise ImportError(f'{name} has no __version__; reinstall the packaged version') Try / catch
try:
import_optional_dependency(name, min_version=minimum)
except ImportError:
# module present but version-less — reinstall or pass errors='ignore'
... Prevention
- Install dependencies from PyPI/conda rather than vendored stubs.
- Check for local same-name files shadowing the package.
- Use pip show <pkg> to confirm installed package metadata is present.
When it happens
Trigger: import_optional_dependency(name, min_version=...) calls get_version on the imported module; if module.__version__ is None/missing, line 80 raises. Also reachable by calling get_version directly on a module lacking __version__.
Common situations: A lightweight/stub package that imports successfully but omits __version__ (some C-extensions, vendored forks, namespace packages); a module shadowed by a local file of the same name that lacks version metadata; an in-development checkout without packaged metadata.
Related errors
- Pandas requires version '{minimum_version}' or newer of '{pa
- `Import {install_name}` failed. {extra} Use pip, conda, or y
- Please upgrade numpy to >= {_min_numpy_ver} to use this pand
- pyarrow>={PYARROW_MIN_VERSION} is required for PyArrow backe
- Unable to import required dependency {_dependency}. Please s
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/f49819a2366e8b3d.
Report an issue: GitHub.