Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Cannot import due to ModuleNotFound 'pytz' #885

Closed

Description

@scizorman

Environment details

  • OS type and version: Ubuntu 20.04
  • Python version: Python 3.9.6
  • pip version: pip 21.2.4
  • google-cloud-bigquery version: 2.24.0

Steps to reproduce

  1. pip install 'google-cloud-bigquery==2.24.0'
  2. from google.cloud import bigquery

Code example

>>> from google.cloud import bigquery

Stack trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/scizorman/dev/tmp/foo/.venv/lib/python3.9/site-packages/google/cloud/bigquery/__init__.py", line 35, in <module>
    from google.cloud.bigquery.client import Client
  File "/home/scizorman/dev/tmp/foo/.venv/lib/python3.9/site-packages/google/cloud/bigquery/client.py", line 71, in <module>
    from google.cloud.bigquery.dataset import Dataset
  File "/home/scizorman/dev/tmp/foo/.venv/lib/python3.9/site-packages/google/cloud/bigquery/dataset.py", line 25, in <module>
    from google.cloud.bigquery.routine import RoutineReference
  File "/home/scizorman/dev/tmp/foo/.venv/lib/python3.9/site-packages/google/cloud/bigquery/routine/__init__.py", line 18, in <module>
    from google.cloud.bigquery.enums import DeterminismLevel
  File "/home/scizorman/dev/tmp/foo/.venv/lib/python3.9/site-packages/google/cloud/bigquery/enums.py", line 21, in <module>
    from google.cloud.bigquery.query import ScalarQueryParameterType
  File "/home/scizorman/dev/tmp/foo/.venv/lib/python3.9/site-packages/google/cloud/bigquery/query.py", line 23, in <module>
    from google.cloud.bigquery.table import _parse_schema_resource
  File "/home/scizorman/dev/tmp/foo/.venv/lib/python3.9/site-packages/google/cloud/bigquery/table.py", line 23, in <module>
    import pytz
ModuleNotFoundError: No module named 'pytz'

.venv/lib/python3.9/site-packages/google/cloud/bigquery/table.py

# Copyright 2015 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Define API Tables."""

from __future__ import absolute_import

import copy
import datetime
import functools
import operator
import pytz
...

Activity

  1. hieumdd commented on Aug 19, 2021

    @hieumdd

    I've found this today.
    setup.py no longer has pytz, while table.py still has import pytz

    Environment details

    • OS type and version: macOS 10.15.6
    • Python version: Python 3.8.5
    • pip version: pip 20.3.3
    • google-cloud-bigquery version: 2.24.0

    Steps to reproduce
    pipenv install google-cloud-bigquery

    • Deploy on GCF with pipenv lock -r > requirements.txt
  2. EDjur commented on Aug 19, 2021

    @EDjur

    Ditto. Also happens on google-cloud-bigquery==2.23.2. Related: googleapis/python-api-core#250

  3. pietrodn commented on Aug 19, 2021

    @pietrodn

    I confirm this issue. On my project, this happened:

    1. Dependabot attempted to update google-api-core from 1.31.2 to 2.0.0
    2. google-api-core==2.0.0 removed the dependency on pytz
    3. No other package depended on pytz, so the package was uninstalled
    4. google-cloud-bigquery implicitly depends on pytz
    5. The tests started failing with this traceback:
      .venv/lib/python3.9/site-packages/google/cloud/bigquery/__init__.py:35: in <module>
          from google.cloud.bigquery.client import Client
      .venv/lib/python3.9/site-packages/google/cloud/bigquery/client.py:71: in <module>
          from google.cloud.bigquery.dataset import Dataset
      .venv/lib/python3.9/site-packages/google/cloud/bigquery/dataset.py:25: in <module>
          from google.cloud.bigquery.routine import RoutineReference
      .venv/lib/python3.9/site-packages/google/cloud/bigquery/routine/__init__.py:18: in <module>
          from google.cloud.bigquery.enums import DeterminismLevel
      .venv/lib/python3.9/site-packages/google/cloud/bigquery/enums.py:21: in <module>
          from google.cloud.bigquery.query import ScalarQueryParameterType
      .venv/lib/python3.9/site-packages/google/cloud/bigquery/query.py:23: in <module>
          from google.cloud.bigquery.table import _parse_schema_resource
      .venv/lib/python3.9/site-packages/google/cloud/bigquery/table.py:23: in <module>
          import pytz
      E   ModuleNotFoundError: No module named 'pytz'
      

    However I see that a commit in master removes the implicit dependency of google-cloud-bigquery on pytz.
    I guess that the problem will be solved when a new release of the BigQuery lib is cut.

  4. aciezkowski commented on Aug 19, 2021

    @aciezkowski

    It seems there's a fix for it here #875 planned for 2.24.1, but it has not been released yet -> #879

  5. added
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Aug 19, 2021
  6. plamut commented on Aug 19, 2021

    @plamut
    Contributor

    Right... the new version of api-core dropped the pytz dependency which the python-bigquery library implicitly depends on.

    A fix is on the way (15 minutes or so if all goes right).

    (and the workaround is to install pytz manually if using an older BigQuery client version)

  7. plamut commented on Aug 19, 2021

    @plamut
    Contributor

    Released. Sorry folks for the inconvenience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions