{"record":{"id":"ec2d210d83404747","repo":"pola-rs/polars","slug":"invalid-value-for-polars-force-pkg-variable","errorCode":null,"errorMessage":"Invalid value for `POLARS_FORCE_PKG` variable: '{_force}'","messagePattern":"Invalid value for `POLARS_FORCE_PKG` variable: '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_plr.py","lineNumber":65,"sourceCode":"    # Each of the Polars variants registers a `_polars...` package that we can import\n    # the PLR from.\n\n    _force = os.environ.get(\"POLARS_FORCE_PKG\")\n    _prefer = os.environ.get(\"POLARS_PREFER_PKG\")\n\n    pkgs = {\"compat\": rt_compat, \"64\": rt_64, \"32\": rt_32}\n    default_prefer = [rt_compat, rt_64, rt_32]\n\n    if _force is not None:\n        try:\n            pkgs[_force]()\n\n            if sys.modules[__name__].__version__ != PKG_VERSION:\n                msg = f\"Polars Rust module for '{_force}' ({sys.modules[__name__].__version__}) did not match version of Python package '{PKG_VERSION}'\"\n                raise ImportError(msg)\n        except KeyError:\n            msg = f\"Invalid value for `POLARS_FORCE_PKG` variable: '{_force}'\"\n            raise ValueError(msg) from None\n    else:\n        preference = default_prefer\n        if _prefer is not None:\n            try:\n                preference.insert(0, pkgs[_prefer])\n            except KeyError:\n                msg = f\"Invalid value for `POLARS_PREFER_PKG` variable: '{_prefer}'\"\n                raise ValueError(msg) from None\n\n        version_warnings = []\n        for pkg in preference:\n            try:\n                pkg()\n\n                if sys.modules[__name__].__version__ != PKG_VERSION:\n                    import warnings\n\n                    version_warnings += [sys.modules[__name__].__version__]","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_plr.py#L47-L83","documentation":"Polars reads POLARS_FORCE_PKG to force a specific Rust extension package from a fixed dict of known packages. If the value is not a key of that dict, the lookup raises KeyError, which Polars converts into a ValueError explaining the invalid variable value.","triggerScenarios":"Exporting POLARS_FORCE_PKG with a name not in the pkgs registry — typos, lowercase/uppercase variants, or a package name that no longer exists in the installed Polars version.","commonSituations":"Copying a POLARS_FORCE_PKG=... line from blog/docs for a different Polars version; typos like polars-lts-cpu= vs polars_lts_cpu; shell profiles exporting stale values.","solutions":["Set POLARS_FORCE_PKG to an exact supported package name (e.g. `polars` or `polars-lts-cpu` — check the pkgs dict in polars/_plr.py for your version)","Remove/unset the variable entirely to use automatic preference: `unset POLARS_FORCE_PKG`","Verify the variable in the active environment: `echo $POLARS_FORCE_PKG` and inspect shell rc files","If a wheel variant was dropped, upgrade or downgrade Polars to a version that still supports that package name"],"exampleFix":"// before\n$ export POLARS_FORCE_PKG=polars-cpu  # ValueError: invalid value\n// after\n$ export POLARS_FORCE_PKG=polars-lts-cpu","handlingStrategy":"validation","validationCode":"import os\nVALID = {'polars', 'polars-lts-cpu', 'polars-u64-idx'}  # see pkgs dict in _plr.py\nv = os.environ.get('POLARS_FORCE_PKG')\nif v and v not in VALID:\n    raise SystemExit(f'POLARS_FORCE_PKG invalid: {v}')","typeGuard":null,"tryCatchPattern":"try:\n    import polars as pl\nexcept ValueError as e:\n    os.environ.pop('POLARS_FORCE_PKG', None)\n    import polars as pl","preventionTips":["Copy package names from Polars docs/source instead of typing from memory","Unset the variable in default environments; enable it only where needed","Grep shell rc/CI files for POLARS_FORCE_PKG when upgrading Polars versions","Pin the exact supported name in Dockerfiles with a comment referencing the Polars version"],"tags":["python","environment-variable","configuration","invalid-value"],"backgroundTag":"invalid-env-var-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}