{"record":{"id":"f49819a2366e8b3d","repo":"pandas-dev/pandas","slug":"can-t-determine-version-for-module-name","errorCode":null,"errorMessage":"Can't determine version for {module.__name__}","messagePattern":"Can't determine version for (.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"pandas/compat/_optional.py","lineNumber":80,"sourceCode":"# these two names are different.\n\nINSTALL_MAPPING = {\n    \"bs4\": \"beautifulsoup4\",\n    \"bottleneck\": \"Bottleneck\",\n    \"jinja2\": \"Jinja2\",\n    \"lxml.etree\": \"lxml\",\n    \"odf\": \"odfpy\",\n    \"python_calamine\": \"python-calamine\",\n    \"sqlalchemy\": \"SQLAlchemy\",\n    \"tables\": \"pytables\",\n}\n\n\ndef get_version(module: types.ModuleType) -> str:\n    version = getattr(module, \"__version__\", None)\n\n    if version is None:\n        raise ImportError(f\"Can't determine version for {module.__name__}\")\n    if module.__name__ == \"psycopg2\":\n        # psycopg2 appends \" (dt dec pq3 ext lo64)\" to its version\n        version = version.split()[0]\n    return version\n\n\n@overload\ndef import_optional_dependency(\n    name: str,\n    extra: str = ...,\n    min_version: str | None = ...,\n    *,\n    errors: Literal[\"raise\"] = ...,\n) -> types.ModuleType: ...\n\n\n@overload\ndef import_optional_dependency(","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/compat/_optional.py#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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`."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import importlib\nm = importlib.import_module(name)\nassert hasattr(m, '__version__'), f'{name} missing __version__'","typeGuard":null,"tryCatchPattern":"try:\n    from pandas.compat._optional import get_version\n    ver = get_version(module)\nexcept ImportError:\n    ver = 'unknown'","preventionTips":["Reinstall dependencies from clean wheels in editable-install trouble.","Verify __version__ exists for any custom dependency before relying on version checks."],"tags":["dependencies","version-check","import-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}