AttributeError: module 'importlib' has no attribute 'util'
AttributeError: module 'importlib' has no attribute 'util'
我刚刚从 Fedora 32 升级到 Fedora 33(Python 3.9 附带)。从那时起 gcloud
命令停止工作:
[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'
来自 GCP 支持的更新
GCP support mentioned 新版本 318.0.0
于 2020.11.10
发布
应该支持 python 3.9
我将我的 gcloud sdk 更新为 318.0.0
,现在看来支持 python 3.9.0。
解决这个问题运行
gcloud components update
Fedora 33 包含 python 2.7 并强制 GCloud SDK 使用它请设置此环境变量
export CLOUDSDK_PYTHON=python2
您可以将此导出命令添加到您的 ~/.bash_profile
Python 3.9 很新,预计 Gcloud SDK 不支持 3.9,它被编写为与 2.7.x & 3.6 - 3.8 兼容(3.8 可能会导致一些兼容性问题我建议使用 3.7)
作为解决方法,将 Python 3.8 或 3.7(这些版本适用于 Gcloud 和大多数 linux 发行版)配置为系统范围的解释器并尝试使用 gcloud 命令。
如果您不想使用Python 2,您可以在Fedora 33 上使用Python 3.8,直到SDK 开始支持Python 3.9。
安装 python 3.8 使用:
sudo dnf install python3.8
您可以通过运行验证您的安装:
python3.8 --version
然后将其设置为 Google Cloud SDK 解释器:
export CLOUDSDK_PYTHON=python3.8
在此之后,SDK 应该可以正常工作。
gcloud 将于 11 月 10 日更新至 318 版本并修复此问题。
对于macOS/Homebrew:
brew install python@3.8
export CLOUDSDK_PYTHON=python3.8
ln -s /usr/local/Cellar/python@3.8/*/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
brew 升级后发生在我身上。适用于 python 3.8.
您需要将 python3.8 设为 shell 路径。我执行了以下几行并且有效
export PATH="/usr/local/opt/python@3.8/bin:$PATH"
alias python=/usr/local/opt/python@3.8/bin/python3
谢谢!
对于 Mac OS 用户
首先你应该运行 brew update
.
如果您遇到此错误:
Error: homebrew-core is a shallow clone. To `brew update` first run:
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core. We don't do this for you automatically to avoid
repeatedly performing an expensive unshallow operation in CI systems (which
should instead be fixed to not use shallow clones). Sorry for the inconvenience!
运行 下一个命令:
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow
现在,
更新python3.8brew upgrade python@3.8
将 python 3.8 添加到 PATH export PATH="/usr/local/opt/python@3.8/bin:$PATH"
在 Cloud SDK 中使用 python 3.8 export CLOUDSDK_PYTHON=python3.8
现在,您可以更新 gcloud 组件 gcloud components update
我刚刚从 Fedora 32 升级到 Fedora 33(Python 3.9 附带)。从那时起 gcloud
命令停止工作:
[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'
来自 GCP 支持的更新
GCP support mentioned 新版本 318.0.0
于 2020.11.10
发布
应该支持 python 3.9
我将我的 gcloud sdk 更新为 318.0.0
,现在看来支持 python 3.9.0。
解决这个问题运行
gcloud components update
Fedora 33 包含 python 2.7 并强制 GCloud SDK 使用它请设置此环境变量
export CLOUDSDK_PYTHON=python2
您可以将此导出命令添加到您的 ~/.bash_profile
Python 3.9 很新,预计 Gcloud SDK 不支持 3.9,它被编写为与 2.7.x & 3.6 - 3.8 兼容(3.8 可能会导致一些兼容性问题我建议使用 3.7)
作为解决方法,将 Python 3.8 或 3.7(这些版本适用于 Gcloud 和大多数 linux 发行版)配置为系统范围的解释器并尝试使用 gcloud 命令。
如果您不想使用Python 2,您可以在Fedora 33 上使用Python 3.8,直到SDK 开始支持Python 3.9。
安装 python 3.8 使用:
sudo dnf install python3.8
您可以通过运行验证您的安装:
python3.8 --version
然后将其设置为 Google Cloud SDK 解释器:
export CLOUDSDK_PYTHON=python3.8
在此之后,SDK 应该可以正常工作。
gcloud 将于 11 月 10 日更新至 318 版本并修复此问题。
对于macOS/Homebrew:
brew install python@3.8
export CLOUDSDK_PYTHON=python3.8
ln -s /usr/local/Cellar/python@3.8/*/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
brew 升级后发生在我身上。适用于 python 3.8.
您需要将 python3.8 设为 shell 路径。我执行了以下几行并且有效
export PATH="/usr/local/opt/python@3.8/bin:$PATH"
alias python=/usr/local/opt/python@3.8/bin/python3
谢谢!
对于 Mac OS 用户
首先你应该运行 brew update
.
如果您遇到此错误:
Error: homebrew-core is a shallow clone. To `brew update` first run:
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core. We don't do this for you automatically to avoid
repeatedly performing an expensive unshallow operation in CI systems (which
should instead be fixed to not use shallow clones). Sorry for the inconvenience!
运行 下一个命令:
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow
现在,
更新python3.8brew upgrade python@3.8
将 python 3.8 添加到 PATH export PATH="/usr/local/opt/python@3.8/bin:$PATH"
在 Cloud SDK 中使用 python 3.8 export CLOUDSDK_PYTHON=python3.8
现在,您可以更新 gcloud 组件 gcloud components update