Issue
I am using Python 3.7 on my raspberry pi3, I got an error that my module importlib doesn't have util, could you tell me how resolve this problem?
If I do:
pi@raspberrypi:~ $ python3
>>> import importlib
>>> dir(importlib)
I get :
['_RELOADING', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__import__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_bootstrap', '_bootstrap_external', '_imp', '_r_long', '_w_long', 'find_loader', 'import_module', 'invalidate_caches', 'reload', 'sys', 'types', 'warnings']
So :
>>> importlib.util
returns:
Traceback (most recent call last): File "", line 1, in AttributeError: module 'importlib' has no attribute 'util'
I tried with Python 3.8 but I got the same results Thank you in advance
Solution
You need to do import importlib.util
:
>>> import importlib.util
>>> dir(importlib.util)
['LazyLoader', 'MAGIC_NUMBER', '_LazyModule', '_RAW_MAGIC_NUMBER', '__builtins__',
'__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__',
'__spec__', '_find_spec', '_find_spec_from_path', '_imp', '_module_to_load',
'_resolve_name', 'abc', 'cache_from_source', 'contextmanager', 'decode_source',
'find_spec', 'functools', 'module_for_loader', 'module_from_spec', 'resolve_name',
'set_loader', 'set_package', 'source_from_cache', 'source_hash',
'spec_from_file_location', 'spec_from_loader', 'sys', 'types', 'warnings']
>>>
relevant docs: importlib.util
Answered By - buran