{"record":{"id":"01bf2918cfb4aa31","repo":"pola-rs/polars","slug":"invalid-value-for-polars-prefer-pkg-variable","errorCode":null,"errorMessage":"Invalid value for `POLARS_PREFER_PKG` variable: '{_prefer}'","messagePattern":"Invalid value for `POLARS_PREFER_PKG` variable: '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_plr.py","lineNumber":73,"sourceCode":"\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__]\n                    warnings.warn(\n                        f\"Skipping Polars' Rust module version '{sys.modules[__name__].__version__}' did not match version of Python package '{PKG_VERSION}'.\",\n                        ImportWarning,\n                        stacklevel=2,\n                    )\n                    continue\n\n                break","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_plr.py#L55-L91","documentation":"POLARS_PREFER_PKG supplies an ordered preference of Rust extension packages Polars should try to load. If a listed name is not a key of the known pkgs dict, Polars raises ValueError with the invalid value. Unlike FORCE_PKG, an invalid PREFER value is not silently skipped — it is a hard configuration error.","triggerScenarios":"Exporting POLARS_PREFER_PKG with a name absent from the pkgs registry — typos, wrong separators, or names valid only in other Polars versions.","commonSituations":"CI config or Dockerfile ENV copied between projects with different Polars versions; guessing package names instead of copying from the registry; shell rc files accumulating stale exports.","solutions":["Use only known package names from the pkgs dict in polars/_plr.py, separated per the documented format","Unset the variable to fall back to the default preference order: `unset POLARS_PREFER_PKG`","Print the current value (`echo $POLARS_PREFER_PKG`) and diff against valid names for your installed Polars","Align Polars version with the source of the config if the name was valid for another version"],"exampleFix":"// before\n$ export POLARS_PREFER_PKG=polars-uvloop  # ValueError: invalid value\n// after\n$ export POLARS_PREFER_PKG=polars-lts-cpu,polars","handlingStrategy":"validation","validationCode":"import os\nVALID = {'polars', 'polars-lts-cpu', 'polars-u64-idx'}  # see pkgs dict in _plr.py\nv = os.environ.get('POLARS_PREFER_PKG')\nif v and any(name not in VALID for name in v.split(',')):\n    raise SystemExit(f'POLARS_PREFER_PKG invalid: {v}')","typeGuard":null,"tryCatchPattern":"try:\n    import polars as pl\nexcept ValueError as e:\n    os.environ.pop('POLARS_PREFER_PKG', None)\n    import polars as pl","preventionTips":["Validate env vars at container/CI start with a preflight script","Keep the preference list minimal and version-pinned","Document valid names next to where the variable is set","Prefer the default preference order unless a specific wheel is required"],"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"}