. Advertisement .
..3..
. Advertisement .
..4..
The error: “AttributeError: module ‘importlib’ has no attribute ‘util’” is a common error that can show up in many ways. In this blog, we will go through some of the ways you can fix this issue. Read on.
What is “AttributeError: module ‘importlib’ has no attribute ‘util’”?
You recently upgraded to Fedora 33. However, you cannot perform the gcloud command at some times. You may have trouble with the following error.
Traceback (most recent call last):
File "/usr/lib64/python3.9/site.py", line 169, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 562, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'
Remainder of file ignored
Traceback (most recent call last):
File "/usr/lib64/google-cloud-sdk/lib/third_party/enum/__init__.py", line 26, in <module>
spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'
How to deal with it?
If you encounter this situation, you do not need to worry too much, see our error handling methods below and choose the method that is suitable for you:
Approach 1: Simply upgrade gcloud
To resolve this problem, simply use:
gcloud components update
Approach 2: On macOS devices
To fix the error, in case you using macOS, run this code below:
brew install [email protected]
export CLOUDSDK_PYTHON=python3.8
ln -s /usr/local/Cellar/[email protected]/*/bin/python3.8 /usr/local/bin/python3.8
gcloud components update
# the issue is now resolved and you can return to python 3.9
unset CLOUDSDK_PYTHON
Approach 3
Use the following program:
>>> 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']
>>> importlib.util
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'importlib' has no attribute 'util'
>>> importlib.util
<module 'importlib.util' from '/usr/lib/python3.5/importlib/util.py'>
>>> dir(importlib)
['_RELOADING', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__import__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_bootstrap', '_bootstrap_external', '_imp', '_r_long', '_w_long', 'abc', 'find_loader', 'import_module', 'invalidate_caches', 'machinery', 'reload', 'sys', 'types', 'util', 'warnings']
Conclusion
We hope you enjoyed our article about the error. With this knowledge, we know that you can fix your error: “AttributeError: module ‘importlib’ has no attribute ‘util’” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
Leave a comment