<@ULVA73B9P> When I run my code locally, it works ...
# ask-marvin
c
@Marvin When I run my code locally, it works correctly. However, when I run it from Prefect Cloud, I get the following error:
ImportError("cannot import name 'Github' from 'github'
m
thought for 257.4 seconds
This usually means the runtime where your flow is executed in Prefect Cloud doesn’t have the PyGithub package (or something is shadowing it). Quick checks: - Confirm you installed the correct package:
pip install PyGithub
(import remains
from github import Github
). - Make sure you don’t have a file or folder named
github.py
or
github/
in your project — that will shadow the PyGithub module. - Verify which work pool you’re using (Process, Docker, Kubernetes) — packaging differs per pool. How to fix by work pool (assuming Prefect 3.x): - Process work pool - Install PyGithub in the same environment where you run the worker:
Copy code
pip install PyGithub
    prefect worker start --pool your-process-pool
- Restart the worker after installing. - Docker work pool - Add PyGithub to your image (recommended): - Put it in
requirements.txt
and rebuild/push your image. - If you use
prefect deploy
with
dockerfile: auto
, it will install from
requirements.txt
automatically. - Or install at runtime with job variables: - In `prefect.yaml`:
Copy code
deployments:
      - name: your-deployment
        entrypoint: path/to/flow.py:flow_fn
        work_pool:
          name: your-docker-pool
          job_variables:
            env:
              EXTRA_PIP_PACKAGES: "PyGithub"
- Or set
EXTRA_PIP_PACKAGES
on the work pool’s base job template in the UI. - Kubernetes work pool - Same pattern as Docker: include PyGithub in the image (via requirements.txt) or set
EXTRA_PIP_PACKAGES: "PyGithub"
in job variables or the pool’s base job template. Helpful docs: - Docker deployments - Kubernetes deployments - Customize job variables - Run flows in local processes If you can share: - Your work pool type - How you’re deploying (prefect.yaml or
flow.deploy
) - Whether you’re building an image or relying on runtime installs …I can give you exact steps tailored to your setup.
c
@Marvin I included PyGithub in my Dockerfile. Below is the code I used for my Dockerfile:
Copy code
FROM prefecthq/prefect:3.2.14-python3.9
COPY . /opt/prefect/Scripts/
WORKDIR /opt/prefect/Scripts/
RUN pip install --no-cache-dir prefect-snowflake GitPython PyGithub "snowflake-connector-python[pandas]==4.0.0" "pandas==2.3.3" "numpy>=2.0,<3" "pyarrow==21.0.0" "prefect[shell]" adlfs s3fs requests pyodbc prefect_azure github && apt-get update && apt-get install -y unixodbc -y curl ca-certificates && curl -sSL -o /usr/local/bin/kubectl <https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl> && chmod +x /usr/local/bin/kubectl
m
thought for 34.7 seconds
You’ve installed both PyGithub and the unrelated package named
github
in your image. The
github
package shadows PyGithub’s module namespace and causes: ImportError: cannot import name 'Github' from 'github' In your Dockerfile, this part is the culprit:
Copy code
... prefect_azure github && ...
Remove
github
and keep only
PyGithub
. Suggested Dockerfile (trimmed to the essentials you shared):
Copy code
FROM prefecthq/prefect:3.2.14-python3.9

COPY . /opt/prefect/Scripts/
WORKDIR /opt/prefect/Scripts/

RUN pip install --no-cache-dir \
    prefect-snowflake \
    GitPython \
    PyGithub \
    "snowflake-connector-python[pandas]==4.0.0" \
    "pandas==2.3.3" \
    "numpy>=2.0,<3" \
    "pyarrow==21.0.0" \
    "prefect[shell]" \
    adlfs \
    s3fs \
    requests \
    pyodbc \
    prefect_azure \
  && apt-get update \
  && apt-get install -y unixodbc curl ca-certificates \
  && curl -sSL -o /usr/local/bin/kubectl https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl \
  && chmod +x /usr/local/bin/kubectl
Notes: - Make sure your Dockerfile literally uses
numpy>=2.0,<3
(Slack often renders `>`/`<` as `>`/`<` in messages). - Also confirm there’s no
github.py
or
github/
folder in your project that could shadow PyGithub. Rebuild and push a fresh image (avoid cached layers), then update your deployment to use the new tag:
Copy code
docker build --no-cache -t your-registry/your-image:fixed .
docker push your-registry/your-image:fixed
Update the deployment’s image to
your-registry/your-image:fixed
and re-run. Optional quick sanity check inside the container:
Copy code
python -c "import github, sys; print('github path:', github.__file__); from github import Github; print('OK:', Github)"
If you’re building/pushing via Prefect (prefect.yaml or flow.deploy), let me know which you use and I can share the exact steps to propagate the new image tag.