AttributeError: module 'importlib' không có thuộc tính 'using'
Tôi vừa nâng cấp từ Fedora 32 lên Fedora 33 (đi kèm với Python 3.9). Kể từ đó gcloudlệnh ngừng hoạt động:
[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'
Trả lời
Cập nhật từ bộ phận hỗ trợ GCP
Hỗ trợ GCP đã đề cập rằng phiên bản mới 318.0.0được phát hành trên 2020.11.10sẽ hỗ trợ python 3.9
Tôi đã cập nhật sdk gcloud của mình lên 318.0.0và bây giờ có vẻ như python 3.9.0 được hỗ trợ.
Để khắc phục sự cố này, hãy chạy
gcloud components update
Fedora 33 bao gồm python 2.7 và để buộc GCloud SDK sử dụng nó, vui lòng đặt biến môi trường này
export CLOUDSDK_PYTHON=python2
Bạn có thể thêm lệnh xuất này vào ~/.bash_profile
Python 3.9 rất mới và dự kiến Gcloud SDK không hỗ trợ 3.9, nó được viết để tương thích với 2.7.x & 3.6 - 3.8 (3.8 có thể gây ra một số vấn đề về tính toán, tôi khuyên bạn nên sử dụng 3.7)
Để giải quyết vấn đề này, hãy định cấu hình Python 3.8 hoặc 3.7 (phiên bản này hoạt động tốt cho Gcloud và hầu hết các bản phân phối linux) làm trình thông dịch trên toàn hệ thống và cố gắng sử dụng các lệnh gcloud.
Đối với macOS / Homebrew:
brew install [email protected]
export CLOUDSDK_PYTHON=python3.8
gcloud components update
Đã xảy ra với tôi sau khi nâng cấp bia. Làm việc với python 3.8.
Bạn cần tạo python3.8 vào đường dẫn shell của mình. Tôi đã thực hiện các dòng sau và nó hoạt động
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
alias python=/usr/local/opt/[email protected]/bin/python3
Cảm ơn bạn!
Nếu không muốn sử dụng Python 2, bạn có thể sử dụng Python 3.8 trên Fedora 33 cho đến khi SDK bắt đầu hỗ trợ Python 3.9.
Cài đặt python 3.8 bằng cách sử dụng:
sudo dnf install python3.8
Bạn có thể xác minh cài đặt của mình bằng cách chạy:
python3.8 --version
Sau đó, đặt nó làm trình thông dịch Google Cloud SDK:
export CLOUDSDK_PYTHON=python3.8
Sau đó, SDK sẽ hoạt động bình thường.
Đối với người dùng Mac OS
Trước hết bạn nên chạy brew update.
Nếu bạn gặp lỗi này:
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!
Chạy các lệnh tiếp theo:
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow
Hiện nay,
Cập nhật python 3.8 brew upgrade [email protected]
Thêm python 3.8 vào PATH export PATH="/usr/local/opt/[email protected]/bin:$PATH"
Sử dụng python 3.8 trong Cloud SDK export CLOUDSDK_PYTHON=python3.8
Bây giờ, bạn có thể cập nhật các thành phần của gcloud gcloud components update