{"id":"7fc0eb6a23dd8a86","repo":"pypa/pip","slug":"os-mkdir-not-supported-on-this-platform","errorCode":null,"errorMessage":"\"os.mkdir\" not supported on this platform.","messagePattern":"\"os\\.mkdir\" not supported on this platform\\.","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":3510,"sourceCode":"    types = _always_object(inspect.getmro(getattr(ob, '__class__', type(ob))))\n    for t in types:\n        if t in registry:\n            return registry[t]\n    # _find_adapter would previously return None, and immediately be called.\n    # So we're raising a TypeError to keep backward compatibility if anyone depended on that behaviour.\n    raise TypeError(f\"Could not find adapter for {registry} and {ob}\")\n\n\ndef ensure_directory(path: StrOrBytesPath):\n    \"\"\"Ensure that the parent directory of `path` exists\"\"\"\n    dirname = os.path.dirname(path)\n    os.makedirs(dirname, exist_ok=True)\n\n\ndef _bypass_ensure_directory(path):\n    \"\"\"Sandbox-bypassing version of ensure_directory()\"\"\"\n    if not WRITE_SUPPORT:\n        raise OSError('\"os.mkdir\" not supported on this platform.')\n    dirname, filename = split(path)\n    if dirname and filename and not isdir(dirname):\n        _bypass_ensure_directory(dirname)\n        try:\n            mkdir(dirname, 0o755)\n        except FileExistsError:\n            pass\n\n\ndef split_sections(s: _NestedStr) -> Iterator[tuple[str | None, list[str]]]:\n    \"\"\"Split a string or iterable thereof into (section, content) pairs\n\n    Each ``section`` is a stripped version of the section header (\"[section]\")\n    and each ``content`` is a list of stripped lines excluding blank lines and\n    comment-only lines.  If there are any such lines before the first section\n    header, they're returned in a first ``section`` of ``None``.\n    \"\"\"\n    section = None","sourceCodeStart":3492,"sourceCodeEnd":3528,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pkg_resources/__init__.py#L3492-L3528","documentation":"Raised as OSError from _bypass_ensure_directory when the global WRITE_SUPPORT flag is falsy on the current platform. WRITE_SUPPORT is set to None on environments where os.mkdir is unavailable (notably Google App Engine standard), so the sandbox-bypassing directory creation helper refuses to run.","triggerScenarios":"Running pkg_resources code that calls _bypass_ensure_directory (used for creating parent directories of scripts/cache) on a platform where os.mkdir is not available, e.g. GAE standard sandbox or a locked-down runtime that strips os.mkdir.","commonSituations":"Deploying an app that imports pkg_resources on Google App Engine, or running in a restricted sandbox that deletes os.mkdir; the helper is invoked when installing/writing scripts or metadata.","solutions":["Move off the restricted platform/runtime (e.g. GAE standard -> a runtime with full filesystem access) if you need directory creation.","Pre-create the target directories out-of-band so _bypass_ensure_directory finds them and skips mkdir.","Avoid the code path that triggers script/cache writing, or pin to a setuptools/pkg_resources version compatible with your sandbox."],"exampleFix":"# before\n# running on GAE standard -> OSError: \"os.mkdir\" not supported\n\n# after\nimport os\nos.makedirs('/tmp/myapp/cache', exist_ok=True)  # pre-create outside sandbox\n# configure pkg_resources to use this writable dir as cache","handlingStrategy":"type-guard","validationCode":"from pip._vendor.pkg_resources import WRITE_SUPPORT\nif WRITE_SUPPORT is None:\n    raise RuntimeError('mkdir unavailable on this platform; pre-create dirs')\n_bypass_ensure_directory(path)","typeGuard":"def can_write() -> bool:\n    from pip._vendor.pkg_resources import WRITE_SUPPORT\n    return WRITE_SUPPORT is not None","tryCatchPattern":"try:\n    _bypass_ensure_directory(path)\nexcept OSError as e:\n    if 'os.mkdir' not in str(e):\n        raise\n    # pre-create directory out of band","preventionTips":["Avoid restricted runtimes (GAE standard) for code that writes via pkg_resources.","Pre-create target directories in deployment scripts."],"tags":["python","pkg-resources","platform","sandbox","filesystem"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}