Google-cloud-python: General: support Python 3.9

Created on 28 Oct 2020  路  3Comments  路  Source: googleapis/google-cloud-python

google-cloud-python is not compatible with Python 3.9

Python 3.9 is becoming the default on popular operating systems (example: Fedora 33)
Upgrading causes google-cloud-python to fail always with the following stack trace:

% gcloud --version
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'

% python --version
Python 3.9.0

% dnf info google-cloud-sdk
Installed Packages
Name         : google-cloud-sdk
Version      : 316.0.0
Release      : 1
Architecture : x86_64
Size         : 358 M
Source       : google-cloud-sdk-316.0.0-1.src.rpm
Repository   : @System
From repo    : google-cloud-sdk

This is a tricky stack trace to unpack, but it looks like inside of Python's importlib initialization, it (accidentally?) imports user-provided code, which happens to re-enter importlib before it's done initializing.

Related to #10442
Also see: https://stackoverflow.com/questions/64010263/gcloud-not-working-with-fedora33-and-python3-9

Workaround: install and use python3.8 for now

Most helpful comment

Even more awful hack workaround:
update the top of gcloud.py to import re before absolutely everything else, so it gets the proper system enum package, and it at least passes a smoke test:

"""gcloud command line tool."""

from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

import re
import os
import sys

All 3 comments

Even more awful hack workaround:
update the top of gcloud.py to import re before absolutely everything else, so it gets the proper system enum package, and it at least passes a smoke test:

"""gcloud command line tool."""

from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

import re
import os
import sys

Hi @stevenschlansker,

This issue tracker is for the google-cloud-* libraries published on PyPI. For support related to the CLI gcloud, please use one of the channels listed here: https://cloud.google.com/sdk/docs/getting-support.

Thank you!

Was this page helpful?
0 / 5 - 0 ratings