AttributeError: el módulo 'importlib' no tiene atributo 'util'

Sep 22 2020

Acabo de actualizar de Fedora 32 a Fedora 33 (que viene con Python 3.9). Desde entonces, el gcloudcomando dejó de funcionar:

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

Respuestas

73 JanHernandez Sep 22 2020 at 13:53

Actualización desde el soporte de GCP

El soporte de GCP mencionó que la nueva versión 318.0.0lanzada 2020.11.10debería ser compatible con Python 3.9

Actualicé mi gcloud sdk a 318.0.0y ahora parece que python 3.9.0 es compatible.

Para solucionar este problema, ejecute

gcloud components update

Fedora 33 incluye python 2.7 y para obligar a GCloud SDK a usarlo, configure esta variable de entorno

export CLOUDSDK_PYTHON=python2

Puede agregar este comando de exportación a su ~/.bash_profile

Python 3.9 es muy nuevo y se espera que Gcloud SDK no admita 3.9, está escrito para ser compatible con 2.7.xy 3.6 - 3.8 (3.8 puede causar algunos problemas de compatibilidad, recomiendo usar 3.7)

Como solución alternativa, configure Python 3.8 o 3.7 (esta versión funciona bien para Gcloud y la mayoría de las distribuciones de Linux) como intérprete de todo el sistema e intente usar los comandos de gcloud.

26 DrNic Nov 04 2020 at 21:18

Para macOS / Homebrew:

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

Me pasó después de una actualización de cerveza. Funciona con Python 3.8.

Necesita hacer python3.8 en su ruta de shell. Ejecuté las siguientes líneas y funcionó

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

¡Gracias!

6 III.6 Oct 28 2020 at 10:47

Si no desea usar Python 2, puede usar Python 3.8 en Fedora 33 hasta que el SDK comience a admitir Python 3.9.

Instale Python 3.8 usando:

sudo dnf install python3.8

Puede verificar su instalación ejecutando:

python3.8 --version

Luego configúrelo como el intérprete del SDK de Google Cloud:

export CLOUDSDK_PYTHON=python3.8

Después de esto, el SDK debería funcionar normalmente.

3 kurkop Dec 10 2020 at 23:39

Para usuarios de Mac OS

Primero que nada deberías correr brew update.

Si tiene este error:

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!

Ejecute los siguientes comandos:

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

Ahora,

Actualización de Python 3.8 brew upgrade [email protected]

Agregar Python 3.8 a PATH export PATH="/usr/local/opt/[email protected]/bin:$PATH"

Usa Python 3.8 en el SDK de Cloud export CLOUDSDK_PYTHON=python3.8

Ahora puedes actualizar los componentes de gcloud gcloud components update