Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import due to ModuleNotFound 'pytz' #885

Closed
scizorman opened this issue Aug 19, 2021 · 6 comments
Closed

Cannot import due to ModuleNotFound 'pytz' #885

scizorman opened this issue Aug 19, 2021 · 6 comments
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@scizorman
Copy link

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
...
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Aug 19, 2021
@hieumdd
Copy link

hieumdd commented Aug 19, 2021

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

@EDjur
Copy link

EDjur commented Aug 19, 2021

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

@pietrodn
Copy link

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.

@aciezkowski
Copy link

aciezkowski commented Aug 19, 2021

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

@plamut plamut added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Aug 19, 2021
@plamut
Copy link
Contributor

plamut commented Aug 19, 2021

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)

@plamut
Copy link
Contributor

plamut commented Aug 19, 2021

Released. Sorry folks for the inconvenience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

6 participants