Repository: dbt-labs/dbt-core

Issue:
[CT-2225] [Bug] Suddenly getting ModuleNotFoundError: No module named 'pytz'
### Is this a new bug in dbt-core?

- [X] I believe this is a new bug in dbt-core
- [X] I have searched the existing issues, and I could not find an existing issue for this bug

### Current Behavior

I am installing dbt-bigquery with meltano (which installs it in a isolated *venv*).

Today when invoking `dbt deps` using `meltano invoke dbt-bigquery:deps` I am getting a stacktrace with 

    ModuleNotFoundError: No module named 'pytz'



### Expected Behavior

`pytz` should be found. I have noted that it is not included in the requirements. So while it's strange that it suddenly started failing, maybe it was more of an accident that it ever worked in the first place?

### Steps To Reproduce

With versions specified as

    dbt-core~=1.3.0
    dbt-bigquery~=1.3.0

invoking `dbt deps` should not throw a ModuleNotFoundError

### Relevant log output

```shell
Traceback (most recent call last):
  File "/workspaces/elt/.meltano/transformers/dbt-bigquery/venv/bin/dbt", line 5, in <module>
    from dbt.main import main
  File "/workspaces/elt/.meltano/transformers/dbt-bigquery/venv/lib/python3.9/site-packages/dbt/main.py", line 24, in <module>
    import dbt.task.build as build_task
  File "/workspaces/elt/.meltano/transformers/dbt-bigquery/venv/lib/python3.9/site-packages/dbt/task/build.py", line 1, in <module>
    from .run import RunTask, ModelRunner as run_model_runner
  File "/workspaces/elt/.meltano/transformers/dbt-bigquery/venv/lib/python3.9/site-packages/dbt/task/run.py", line 8, in <module>
    from .compile import CompileRunner, CompileTask
  File "/workspaces/elt/.meltano/transformers/dbt-bigquery/venv/lib/python3.9/site-packages/dbt/task/compile.py", line 4, in <module>
    from .runnable import GraphRunnableTask
  File "/workspaces/elt/.meltano/transformers/dbt-bigquery/venv/lib/python3.9/site-packages/dbt/task/runnable.py", line 11, in <module>
    from .printer import (
  File "/workspaces/elt/.meltano/transformers/dbt-bigquery/venv/lib/python3.9/site-packages/dbt/task/printer.py", line 22, in <module>
    from dbt.tracking import InvocationProcessor
  File "/workspaces/elt/.meltano/transformers/dbt-bigquery/venv/lib/python3.9/site-packages/dbt/tracking.py", line 25, in <module>
    import pytz
ModuleNotFoundError: No module named 'pytz'
```


### Environment

```markdown
- OS: Linux (fresh docker container inside virtual environment)
- Python: 3.9
- dbt: 1.3.1 (~=1.3.0)
```


### Which database adapter are you using with dbt?

other (mention it in "Additional Context")

### Additional Context

_No response_


Discussion:
Workaround I've found is to specify `pytz` explicitly in the meltano config as so:

```
  transformers:
    - name: dbt-bigquery
      variant: dbt-labs
      pip_url: dbt-core~=1.3.0 dbt-bigquery~=1.3.0 pytz==2021.1
```

but ideally dbt should define it's dependencies properly


Facing this as well went with the same fix.
If I see correctly it's because of the `Babel` package (included indirectly by `agate`). They've just released version 2.12 which incudes `pytz` only if you have python < 3.9.
https://github.com/python-babel/babel/blob/v2.12.0/setup.py

```
# Python 3.9 and later include zoneinfo which replaces pytz
'pytz>=2015.7; python_version<"3.9"',
```

I think if dbt uses `pytz` directly it should specify it explicitly in reqs.
Pinning Babel to ver 2.11.0 should also work.

Resolving patch:
diff --git a/core/setup.py b/core/setup.py
--- a/core/setup.py
+++ b/core/setup.py
@@ -65,6 +65,7 @@
         "dbt-extractor~=0.4.1",
         "typing-extensions>=3.7.4",
         "werkzeug>=1,<3",
+        "pytz>=2015.7",
         # the following are all to match snowflake-connector-python
         "requests<3.0.0",
         "idna>=2.5,<4",


Test patch: