Cannot create a path from a zipped resource with Python 3.6
I'm using Python 3.6.4. I'm trying to access a resource in a whl file. Using the following code:
import sys, importlib_resources
sys.path.append('path/to/my/wheel/demo_package.whl')
import demo_package
with importlib_resources.path('demo_package', 'somefile.txt') as p:
print(str(p))
This leads to a FileNotFoundError: [Errno 2] No such file or directory
error.
I tried a couple of things and I figured out that the imported package has a loader=<zipimporter object>
. But this object does not have any get_resource_reader
method.
I noticed that in Python 3.7 this method is now defined on zipimporter class. So my question is basically: can we use this backport for zipped files with Python less than 3.7?
Edited by Daniel Gillet