Charlie Nash
11/24/2025, 9:51 PMImportError("cannot import name 'Github' from 'github'Marvin
11/24/2025, 9:51 PMMarvin
11/24/2025, 9:56 PMpip 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:
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`:
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.Charlie Nash
11/24/2025, 9:57 PMFROM 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/kubectlMarvin
11/24/2025, 9:58 PMMarvin
11/24/2025, 9:58 PMgithub 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:
... prefect_azure github && ...
Remove github and keep only PyGithub.
Suggested Dockerfile (trimmed to the essentials you shared):
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:
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:
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.