Github Actions with pandas data loader on Observable Framework

hello,

I am trying to implement Github Actions upon pushing my Observable Framework repo to the main branch (identical to the one on the official website, only without the scheduled run):

name: Deploy

on:
  # Run this workflow whenever a new commit is pushed to main.
  push: {branches: [main]}
  # Run this workflow when triggered manually in GitHub’s UI.
  workflow_dispatch: {}

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - run: npm ci
      - run: npm run build
      - name: Deploy to Observable Cloud
        # This parameter to `--message` will use the latest commit message
        run: npm run deploy -- --message "$(git log -1 --pretty=%s)"
        env:
          # Authentication information. See below for how to set this up.
          OBSERVABLE_TOKEN: ${{ secrets.OBSERVABLE_TOKEN }}

My project includes a data loader (e.g., dataloader.csv.py) which contains a pandas import:

import pandas as pd

However, npm run build fails after encountering the following error:

Traceback (most recent call last):
  File "/home/runner/work/projects/src/data/dataloader.csv.py", line 3, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'
load src/data/dataloader.csv.py → [missing] error in 94ms: loader exited with code 1

Unexpected error: loader exited with code 1

As importing pandas works with my local computer, I guess the program refers to my local python environment somehow, which I haven’t understood yet.

How can I know the path to the python environment is used? Also, what would be the best practice for using a virtual environment with the Observable Framework project?

Thank you

Okay, here is a quick fix:

  1. Create a requirements.txt file in my repo:
pandas
  1. Update the GitHub Actions workflow to set up Python and install dependencies:
name: Deploy

on:
  push: {branches: [main]}
  workflow_dispatch: {}

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.x'
      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - run: npm ci
      - run: npm run build
      - name: Deploy to Observable Cloud
        run: npm run deploy -- --message "$(git log -1 --pretty=%s)"
        env:
          OBSERVABLE_TOKEN: ${{ secrets.OBSERVABLE_TOKEN }}