AttributeError: modul 'importlib' tidak memiliki atribut 'util'

Sep 22 2020

Saya baru saja meningkatkan dari Fedora 32 ke Fedora 33 (yang dilengkapi dengan Python 3.9). Sejak itu gcloudperintah berhenti bekerja:

[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'

Jawaban

73 JanHernandez Sep 22 2020 at 13:53

Pembaruan dari dukungan GCP

Dukungan GCP menyebutkan bahwa versi baru yang 318.0.0dirilis pada 2020.11.10harus mendukung python 3.9

Saya memperbarui sdk gcloud saya menjadi 318.0.0dan sekarang sepertinya python 3.9.0 didukung.

Untuk memperbaiki masalah ini, jalankan

gcloud components update

Fedora 33 menyertakan python 2.7 dan untuk memaksa GCloud SDK untuk menggunakannya, setel variabel lingkungan ini

export CLOUDSDK_PYTHON=python2

Anda dapat menambahkan perintah ekspor ini ke file ~/.bash_profile

Python 3.9 sangat baru dan diharapkan Gcloud SDK tidak mendukung 3.9, itu ditulis agar kompatibel dengan 2.7.x & 3.6 - 3.8 (3.8 dapat menyebabkan beberapa masalah compat, saya sarankan untuk menggunakan 3.7)

Sebagai solusinya, konfigurasikan Python 3.8 atau 3.7 (versi ini berfungsi dengan baik untuk Gcloud dan sebagian besar distro linux) sebagai interpreter seluruh sistem dan coba gunakan perintah gcloud.

26 DrNic Nov 04 2020 at 21:18

Untuk macOS / Homebrew:

brew install [email protected]
export CLOUDSDK_PYTHON=python3.8
gcloud components update
10 Shishir Nov 09 2020 at 10:47

Terjadi pada saya setelah peningkatan minuman. Bekerja dengan python 3.8.

Anda perlu membuat python3.8 menjadi jalur shell Anda. Saya mengeksekusi baris berikut dan berhasil

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
alias python=/usr/local/opt/[email protected]/bin/python3

Terima kasih!

6 III.6 Oct 28 2020 at 10:47

Jika Anda tidak ingin menggunakan Python 2, Anda dapat menggunakan Python 3.8 di Fedora 33 hingga SDK mulai mendukung Python 3.9.

Instal python 3.8 menggunakan:

sudo dnf install python3.8

Anda dapat memverifikasi instalasi Anda dengan menjalankan:

python3.8 --version

Kemudian setel sebagai interpreter Google Cloud SDK:

export CLOUDSDK_PYTHON=python3.8

Setelah ini SDK akan bekerja secara normal.

3 kurkop Dec 10 2020 at 23:39

Untuk Pengguna Mac OS

Pertama-tama Anda harus lari brew update.

Jika Anda mengalami kesalahan ini:

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!

Jalankan perintah selanjutnya:

git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow

Sekarang,

Perbarui python 3.8 brew upgrade [email protected]

Tambahkan python 3.8 ke PATH export PATH="/usr/local/opt/[email protected]/bin:$PATH"

Gunakan python 3.8 di Cloud SDK export CLOUDSDK_PYTHON=python3.8

Sekarang, Anda dapat mengupdate komponen gcloud gcloud components update