{"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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/compat/_optional.py#L62-L98","documentation":"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).","triggerScenarios":"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__.","commonSituations":"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.","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)."],"exampleFix":"# before — local 'tables.py' shadows pytables, no __version__\nimport_optional_dependency('tables', min_version='3.0')\n\n# after\npip install --force-reinstall tables  # or rename/remove the shadowing file","handlingStrategy":"validation","validationCode":"import importlib\nmod = importlib.import_module(name)\nif not hasattr(mod, '__version__'):\n    raise ImportError(f'{name} has no __version__; reinstall the packaged version')","typeGuard":null,"tryCatchPattern":"try:\n    import_optional_dependency(name, min_version=minimum)\nexcept ImportError:\n    # module present but version-less — reinstall or pass errors='ignore'\n    ...","preventionTips":["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."],"tags":["compat","dependencies","version","importerror","optional-dependency"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}