Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 模块';importlib';没有属性';util';_Python_Python 3.x_Raspberry Pi_Python Importlib - Fatal编程技术网

Python 模块';importlib';没有属性';util';

Python 模块';importlib';没有属性';util';,python,python-3.x,raspberry-pi,python-importlib,Python,Python 3.x,Raspberry Pi,Python Importlib,我在raspberry pi3上使用Python3.7,我的模块importlib没有util,您能告诉我如何解决这个问题吗 如果我这样做: pi@raspberrypi:~ $ python3 >>> import importlib >>> dir(importlib) 我得到: ['_RELOADING', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__import

我在raspberry pi3上使用Python3.7,我的模块importlib没有util,您能告诉我如何解决这个问题吗

如果我这样做:

pi@raspberrypi:~ $ python3
>>> import importlib
>>> dir(importlib)
我得到:

['_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']
因此:

返回:

回溯(最近一次呼叫最后一次): 文件“”,第1行,在 AttributeError:模块“importlib”没有属性“util”

我尝试使用Python3.8,但得到了相同的结果
提前感谢您

您需要执行导入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']
>>> 

相关文档:

谢谢@buran它可以工作了
>>> 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']
>>>