{"record":{"id":"bc534d593f74a2e4","repo":"pypa/pip","slug":"os-rename-and-os-unlink-are-not-supported-on-t","errorCode":null,"errorMessage":"\"os.rename\" and \"os.unlink\" are not supported on this platform","messagePattern":"\"os\\.rename\" and \"os\\.unlink\" are not supported on this platform","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":2042,"sourceCode":"        size = zip_stat.file_size\n        # ymdhms+wday, yday, dst\n        date_time = zip_stat.date_time + (0, 0, -1)\n        # 1980 offset already done\n        timestamp = time.mktime(date_time)\n        return timestamp, size\n\n    # FIXME: 'ZipProvider._extract_resource' is too complex (12)\n    def _extract_resource(self, manager: ResourceManager, zip_path) -> str:  # noqa: C901\n        if zip_path in self._index():\n            for name in self._index()[zip_path]:\n                last = self._extract_resource(manager, os.path.join(zip_path, name))\n            # return the extracted directory name\n            return os.path.dirname(last)\n\n        timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])\n\n        if not WRITE_SUPPORT:\n            raise OSError(\n                '\"os.rename\" and \"os.unlink\" are not supported on this platform'\n            )\n        try:\n            if not self.egg_name:\n                raise OSError(\n                    '\"egg_name\" is empty. This likely means no egg could be found from the \"module_path\".'\n                )\n            real_path = manager.get_cache_path(self.egg_name, self._parts(zip_path))\n\n            if self._is_current(real_path, zip_path):\n                return real_path\n\n            outf, tmpnam = _mkstemp(\n                \".$extract\",\n                dir=os.path.dirname(real_path),\n            )\n            os.write(outf, self.loader.get_data(zip_path))\n            os.close(outf)","sourceCodeStart":2024,"sourceCodeEnd":2060,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L2024-L2060","documentation":"Raised as OSError by ZipProvider._extract_resource() when the module-level WRITE_SUPPORT flag is False. That flag is set False if `from os import mkdir, rename, unlink` raises ImportError at import time — which happens on platforms without these OS primitives (e.g. Google App Engine classic sandbox). Extraction requires os.rename/os.unlink to atomically write temp files, so it is unsupported.","triggerScenarios":"Triggering resource extraction from a zip/egg on a platform where os.mkdir/os.rename/os.unlink are unavailable — historically Google App Engine's Python 2 sandbox or similar restricted runtimes.","commonSituations":"Deploying pkg_resources-based code to a restricted sandbox (GAE classic) that blocks filesystem write/rename/unlink; exotic embedded runtimes lacking full os support.","solutions":["Avoid resource_filename()/extraction on write-restricted platforms; use resource_stream()/resource_string() to read directly.","Pre-extract resources to disk at deploy/build time so no runtime extraction is needed.","Move to a runtime with full os support, or use importlib.resources which can serve zip contents without extraction."],"exampleFix":"// before\n# on a platform without os.rename/os.unlink\npath = resource_filename('mypkg', 'data.txt')  # raises OSError\n// after\n# read directly from the archive, no extraction\nstream = resource_stream('mypkg', 'data.txt')","handlingStrategy":"fallback","validationCode":"import os\ntry:\n    from os import mkdir, rename, unlink\n    WRITE_OK = True\nexcept ImportError:\n    WRITE_OK = False\nif not WRITE_OK:\n    # use stream-based access; extraction unavailable","typeGuard":null,"tryCatchPattern":"try:\n    path = resource_filename('pkg', name)\nexcept OSError:\n    stream = resource_stream('pkg', name)  # fallback: no extraction","preventionTips":["On write-restricted platforms, use resource_stream()/resource_string().","Pre-extract resources at build time for sandboxed deployments.","Avoid pkg_resources extraction on GAE/sandboxed runtimes."],"tags":["pkg-resources","resources","platform","extraction","gae"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}