pandas-dev/pandas · error · ImportError
Can't determine version for
Error message
Can't determine version for {module.__name__} What it means
Raised by `get_version` in pandas.compat._optional when an imported module has no `__version__` attribute. pandas requires version metadata to enforce minimum-version checks for optional dependencies; without it, the safety check cannot run. The message names the offending module so the user can identify which dependency is misbehaving.
Solutions
- Reinstall the offending dependency from a clean wheel: `pip install --force-reinstall <name>`.
- Verify in a fresh interpreter: `python -c 'import <mod>; print(getattr(<mod>, "__version__", None))'`.
- If the dependency genuinely lacks `__version__`, raise an issue upstream or pin a version that has it.
- If you control the dependency, set `__version__` in its `__init__.py`.
Defensive patterns
Strategy: try-catch
Validate before calling
import importlib
m = importlib.import_module(name)
assert hasattr(m, '__version__'), f'{name} missing __version__' Try / catch
try:
from pandas.compat._optional import get_version
ver = get_version(module)
except ImportError:
ver = 'unknown' Prevention
- Reinstall dependencies from clean wheels in editable-install trouble.
- Verify __version__ exists for any custom dependency before relying on version checks.
When it happens
Trigger: Importing an optional dependency whose package did not set `__version__` (some pure-Python packages or namespace packages); pre-release or local editable installs missing version metadata; a stub/shim module shadowing the real package.
Common situations: Editable installs (`pip install -e .`) of a dependency that don't bake in version; some conda environments shipping a module without `__version__`; namespace package collisions.
Related errors
- `Import ` failed. Use pip, conda, or your preferred package…
- Pandas requires version
- Please upgrade numpy to >=
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/f49819a2366e8b3d.
Report an issue: GitHub.
Appendix: 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 3b7651241d)