AttributeError:模块"importlib"没有属性"util" [英] AttributeError: module 'importlib' has no attribute 'util'
问题描述
我刚刚从Fedora 32升级到Fedora 33(Python 3.9附带).此后,gcloud
命令停止工作:
I've just upgraded from Fedora 32 to Fedora 33 (which comes with Python 3.9). Since then gcloud
command stopped working:
[guy@Gandalf32 ~]$ gcloud
Error processing line 3 of /home/guy/.local/lib/python3.9/site-packages/XStatic-1.0.2-py3.9-nspkg.pth:
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/gcloud.py", line 104, in <module>
main()
File "/usr/lib64/google-cloud-sdk/lib/gcloud.py", line 62, in main
from googlecloudsdk.core.util import encoding
File "/usr/lib64/google-cloud-sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
from googlecloudsdk.core.util import importing
File "/usr/lib64/google-cloud-sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
import imp
File "/usr/lib64/python3.9/imp.py", line 23, in <module>
from importlib import util
File "/usr/lib64/python3.9/importlib/util.py", line 2, in <module>
from . import abc
File "/usr/lib64/python3.9/importlib/abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "/usr/lib64/python3.9/typing.py", line 26, in <module>
import re as stdlib_re # Avoid confusion with the re we export.
File "/usr/lib64/python3.9/re.py", line 124, in <module>
import enum
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'
推荐答案
更新
Fedora 33包含python 2.7,并且要强制GCloud SDK使用它,请设置此环境变量
Fedora 33 includes python 2.7 and to force GCloud SDK to use it please set this environment variable
export CLOUDSDK_PYTHON=python2
您可以将此导出命令添加到~/.bash_profile
You can add this export command to your ~/.bash_profile
Python 3.9即将发布,预计Gcloud SDK不支持3.9,它被编写为与2.7.x& 3.6-3.8
Python 3.9 is on release candidate and is expected that Gcloud SDK not support 3.9, it is written for be compatible with 2.7.x & 3.6 - 3.8
作为一种解决方法,将Python 3.8或3.7(此版本适用于Gcloud和大多数Linux发行版)作为系统范围的解释器,并尝试使用gcloud命令.
As a workaround, configure Python 3.8 or 3.7 (this versions works well for Gcloud and most of linux distros) as system wide interpreter and try to use gcloud commands.
Fedora 33不能普遍使用,并且可能与某些软件不兼容.
Fedora 33 is not in general availability and is expected some software incompatibility.
您可以通过打开功能请求通过Google公共问题跟踪工具实现兼容性.
You can share your findings with the Gcloud SDK team by opening a Feature request for compatibility via Google public issue tracker.
这篇关于AttributeError:模块"importlib"没有属性"util"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!