{"id":"4bd148c9ea514c03","repo":"pypa/pip","slug":"egg-name-is-empty-this-likely-means-no-egg-coul","errorCode":null,"errorMessage":"\"egg_name\" is empty. This likely means no egg could be found from the \"module_path\".","messagePattern":"\"egg_name\" is empty\\. This likely means no egg could be found from the \"module_path\"\\.","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":2047,"sourceCode":"        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)\n            utime(tmpnam, (timestamp, timestamp))\n            manager.postprocess(tmpnam, real_path)\n\n            try:\n                rename(tmpnam, real_path)","sourceCodeStart":2029,"sourceCodeEnd":2065,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pkg_resources/__init__.py#L2029-L2065","documentation":"Raised as OSError by ZipProvider._extract_resource() when self.egg_name is empty during the extraction of a zipped resource. This is the second guard inside extraction (after the WRITE_SUPPORT check): extraction computes a cache path from egg_name and the zip-relative parts, so an empty egg_name makes cache path computation meaningless. egg_name is empty because EggProvider._setup_prefix found no egg-named ancestor among the module_path parents.","triggerScenarios":"Calling resource_filename()/get_resource_filename() (or any API that forces extraction) on a module inside a zip archive that is not recognized as an egg, so egg_name is None/empty and the cache path cannot be derived.","commonSituations":"Zipimporting a plain .zip or .pyz (zipapp) and requesting a filesystem path for a resource; the archive lacks egg naming conventions so _setup_prefix never calls _set_egg.","solutions":["Read the resource as bytes (resource_string/resource_stream) instead of requesting an extracted filename.","Package the archive as an .egg or ensure EGG-INFO metadata exists so egg_name is populated.","Use importlib.resources (files()/as_file()) which handles zip-backed extraction without egg naming."],"exampleFix":"// before\npath = pkg_resources.resource_filename('mymod', 'data.bin')  # OSError: egg_name empty\n\n// after\ndata = pkg_resources.resource_string('mymod', 'data.bin')  # no egg_name needed","handlingStrategy":"validation","validationCode":"import pkg_resources\n\ndef safe_extract_or_read(module, name):\n    provider = pkg_resources.get_provider(module)\n    if not getattr(provider, 'egg_name', None):\n        return ('bytes', pkg_resources.resource_string(module, name))\n    return ('path', pkg_resources.resource_filename(module, name))","typeGuard":"def provider_has_egg_name(provider) -> bool:\n    return bool(getattr(provider, 'egg_name', None))","tryCatchPattern":"try:\n    path = pkg_resources.resource_filename(pkg, name)\nexcept OSError as e:\n    if 'egg_name' in str(e) and 'empty' in str(e):\n        data = pkg_resources.resource_string(pkg, name)\n    else:\n        raise","preventionTips":["Read zip resources as bytes when egg_name is unavailable.","Repackage plain zips as .egg to enable extraction.","Use importlib.resources for zip-backed resources without egg semantics."],"tags":["pkg-resources","zip","egg","extraction","egg-name"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}