{"record":{"id":"2c08b72b318a4b01","repo":"pypa/pip","slug":"resource-filename-only-supported-for-egg-not","errorCode":null,"errorMessage":"resource_filename() only supported for .egg, not .zip","messagePattern":"resource_filename\\(\\) only supported for \\.egg, not \\.zip","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":2011,"sourceCode":"        if fspath.startswith(self.zip_pre):\n            return fspath[len(self.zip_pre) :]\n        raise AssertionError(\"%s is not a subpath of %s\" % (fspath, self.zip_pre))\n\n    def _parts(self, zip_path):\n        # Convert a zipfile subpath into an egg-relative path part list.\n        # pseudo-fs path\n        fspath = self.zip_pre + zip_path\n        if fspath.startswith(self.egg_root + os.sep):\n            return fspath[len(self.egg_root) + 1 :].split(os.sep)\n        raise AssertionError(\"%s is not a subpath of %s\" % (fspath, self.egg_root))\n\n    @property\n    def zipinfo(self):\n        return self._zip_manifests.load(self.loader.archive)\n\n    def get_resource_filename(self, manager: ResourceManager, resource_name: str):\n        if not self.egg_name:\n            raise NotImplementedError(\n                \"resource_filename() only supported for .egg, not .zip\"\n            )\n        # no need to lock for extraction, since we use temp names\n        zip_path = self._resource_to_zip(resource_name)\n        eagers = self._get_eager_resources()\n        if '/'.join(self._parts(zip_path)) in eagers:\n            for name in eagers:\n                self._extract_resource(manager, self._eager_to_zip(name))\n        return self._extract_resource(manager, zip_path)\n\n    @staticmethod\n    def _get_date_and_size(zip_stat):\n        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","sourceCodeStart":1993,"sourceCodeEnd":2029,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L1993-L2029","documentation":"Raised by ZipProvider.get_resource_filename() when self.egg_name is empty/falsy. ZipProvider extracts zip-archived resources to a cache directory keyed by the egg name; without an egg name there is no stable extraction directory, so it refuses. This indicates the resource lives in a plain .zip rather than a named .egg, which this code path does not support for filesystem extraction.","triggerScenarios":"Calling resource_filename() (which routes to get_resource_filename) for a package imported from a .zip archive that is not an .egg and has no egg name set, so self.egg_name is ''.","commonSituations":"Packaging code in a plain .zip and adding it to sys.path; an import hook that serves modules from a zip without egg metadata; legacy zipped modules without EGG-INFO.","solutions":["Use resource_stream()/resource_string() instead of resource_filename() to read zip contents without extraction.","Package the code as an .egg (with EGG-INFO) so egg_name is populated.","Install the package normally on the filesystem rather than running from a bare .zip."],"exampleFix":"// before\n# module loaded from plain .zip, no egg_name -> NotImplementedError\npath = resource_filename('mypkg', 'data.txt')\n// after\n# read bytes directly without extraction\ndata = resource_string('mypkg', 'data.txt')","handlingStrategy":"fallback","validationCode":"# Check if provider is a ZipProvider without egg_name before calling resource_filename\nfrom pkg_resources import ZipProvider\nif isinstance(provider, ZipProvider) and not provider.egg_name:\n    # use stream-based access instead\n    data = resource_string('pkg', name)","typeGuard":null,"tryCatchPattern":"try:\n    path = resource_filename('pkg', name)\nexcept NotImplementedError:\n    data = resource_string('pkg', name)  # fallback: read bytes","preventionTips":["Prefer resource_stream()/resource_string() for zipped packages.","Package as .egg or install on filesystem if you need real paths."],"tags":["pkg-resources","resources","zip","egg","extraction"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}