Lack of support for importlib_resources
See original GitHub issueHey,
While evaluating nuitka for a somewhat larger problem of mine, I hit a problem due to using importlib_resources
. The problem seems to be that nuitka doesn’t set module.__spec__.module_search_locations
for packages to a list or string as requested by PEP451.
Consider the minimal example bar.py
:
# bar.py
import importlib_resources
% python -m nuitka --follow-imports bar.py
Nuitka:WARNING:/home/thomas/temp/gna/lib/python3.5/site-packages/importlib_resources/_py2.py:9: Cannot find 'pathlib2' in package 'importlib_resources' as absolute import (tried pathlib2).
% ./bar.bin
ModuleSpec(name='importlib_resources', loader=<class '_nuitka_compiled_modules_loader'>)
Traceback (most recent call last):
File "/home/thomas/temp/bar.py", line 1, in <module>
import importlib_resources
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "/home/thomas/temp/gna/lib/python3.5/site-packages/importlib_resources/__init__.py", line 36, in <module importlib_resources>
__version__ = read_text('importlib_resources', 'version.txt').strip()
File "/home/thomas/temp/gna/lib/python3.5/site-packages/importlib_resources/_py3.py", line 158, in read_text
package = _get_package(package)
File "/home/thomas/temp/gna/lib/python3.5/site-packages/importlib_resources/_py3.py", line 41, in _get_package
raise TypeError('{!r} is not a package'.format(package))
TypeError: 'importlib_resources' is not a package
Checking the corresponding line, this error is raised due to module.__spec__.module_search_locations is None
.
The problem is not restricted to importlib_resources
but also appears when loading resources via importlib.resources
on newer python. Grepping for module_search_locations
, I can see that notably six
assigns this as empty list in some locations, and refers to PEP451 which in turn says that this attribute must be set to a list or string whenever the object is a package.
I tried this in a virtualenv with both py3.5 and py3.7 with the stable version 0.6.0.6
from PyPI as well as 0.6.1rc9
from your download page:
% python -m nuitka --version
0.6.0.6
Python: 3.5.5 (default, Sep 6 2018, 12:31:21)
Executable: /home/thomas/temp/gna/bin/python
OS: Linux
Arch: x86_64
Best, Thomas
PS: thanks for all your work on this wonderful project:)
Issue Analytics
- State:
- Created 5 years ago
- Comments:20 (13 by maintainers)
Top GitHub Comments
Great! It now works like a charm!
Seems this should be easy, I will look into this and see if I can include it for 0.6.1 still.
Nuitka starting having these
__spec__
values a while ago, but apparently doesn’t create them fully compatible. Seems it would be enough to assign the__path__
value to it.