AttributeError: Das Modul 'importlib' hat kein Attribut 'util'.

Sep 22 2020

Ich habe gerade ein Upgrade von Fedora 32 auf Fedora 33 (das mit Python 3.9 geliefert wird) durchgeführt. Seitdem gcloudfunktioniert der Befehl nicht mehr:

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

Antworten

73 JanHernandez Sep 22 2020 at 13:53

Update von der GCP-Unterstützung

Die GCP-Unterstützung erwähnte, dass die neue Version, auf der 318.0.0veröffentlicht wurde, 2020.11.10Python 3.9 unterstützen sollte

Ich habe mein gcloud sdk auf aktualisiert 318.0.0und sieht nun so aus, als würde Python 3.9.0 unterstützt.

Um dieses Problem zu beheben, führen Sie es aus

gcloud components update

Fedora 33 enthält Python 2.7. Um das GCloud SDK zur Verwendung zu zwingen, legen Sie bitte diese Umgebungsvariable fest

export CLOUDSDK_PYTHON=python2

Sie können diesen Exportbefehl zu Ihrem hinzufügen ~/.bash_profile

Python 3.9 ist sehr neu und es wird erwartet, dass das Gcloud SDK 3.9 nicht unterstützt. Es wurde geschrieben, um mit 2.7.x und 3.6 - 3.8 kompatibel zu sein (3.8 kann einige Kompatibilitätsprobleme verursachen, die ich für die Verwendung von 3.7 empfehle.)

Um dieses Problem zu umgehen, konfigurieren Sie Python 3.8 oder 3.7 (diese Version funktioniert gut für Gcloud und die meisten Linux-Distributionen) als systemweiten Interpreter und versuchen Sie, gcloud-Befehle zu verwenden.

26 DrNic Nov 04 2020 at 21:18

Für macOS / Homebrew:

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

Ist mir nach einem Brau-Upgrade passiert. Funktioniert mit Python 3.8.

Sie müssen python3.8 in Ihren Shell-Pfad einfügen. Ich habe folgende Zeilen ausgeführt und es hat funktioniert

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

Vielen Dank!

6 III.6 Oct 28 2020 at 10:47

Wenn Sie Python 2 nicht verwenden möchten, können Sie Python 3.8 unter Fedora 33 verwenden, bis das SDK Python 3.9 unterstützt.

Installieren Sie Python 3.8 mit:

sudo dnf install python3.8

Sie können Ihre Installation überprüfen, indem Sie Folgendes ausführen:

python3.8 --version

Stellen Sie es dann als Google Cloud SDK-Interpreter ein:

export CLOUDSDK_PYTHON=python3.8

Danach sollte das SDK normal funktionieren.

3 kurkop Dec 10 2020 at 23:39

Für Mac OS Benutzer

Zunächst sollten Sie laufen brew update.

Wenn Sie diesen Fehler haben:

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!

Führen Sie die nächsten Befehle aus:

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

Jetzt,

Aktualisieren Sie Python 3.8 brew upgrade [email protected]

Fügen Sie Python 3.8 zu PATH hinzu export PATH="/usr/local/opt/[email protected]/bin:$PATH"

Verwenden Sie Python 3.8 im Cloud SDK export CLOUDSDK_PYTHON=python3.8

Jetzt können Sie gcloud-Komponenten aktualisieren gcloud components update