https://pulumi.com logo
#python
Title
# python
p

purple-cricket-59216

02/01/2024, 2:38 PM
Hey all anyone have a working example of a PR GitAction that works with Python venv? I have it working from the cli with venv but when called through GitActions i receive module import errors. ModuleNotFoundError: No module named 'pulumi' This is what im currently trying to make work. - run: python3 -m venv venv - run: . venv/bin/activate - run: which python - run: python --version - run: pip install -r requirements.txt - uses: pulumi/actions@v3
m

millions-furniture-75402

02/01/2024, 2:52 PM
Conceptually, GitHub Actions isn't behaving like a local shell script would. The
run
keyword isn't doing what you think. Each run is a separate process, you won't still be inside your
venv
on the next step. In this case, I think you want the
setup-python
action which it setup python in a runner and persist that runtime across steps: https://github.com/actions/setup-python https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun https://www.pulumi.com/docs/using-pulumi/continuous-delivery/github-actions/
d

dry-keyboard-94795

02/01/2024, 3:01 PM
Additional to that, if you'd like to use that venv directory still, you need to activate + pip install in the same run, or just use pip from the venv directory explicitly:
venv/bin/pip install -r requirements.txt
p

purple-cricket-59216

02/01/2024, 3:19 PM
Thanks knowing that about run helps. Currently i am using users: actions/setup-python@v2.
Copy code
name: Pulumi
on:
  - pull_request
jobs:
  preview:
    name: Preview
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.11
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-region: ${{ secrets.AWS_REGION }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      - run: python3 -m venv venv 
      - run: . venv/bin/activate
      - run: which python
      - run: python --version
      - run: pip install -r requirements.txt
      - uses: pulumi/actions@v3
        with:
          command: preview
          stack-name: org/stackname # When using an individual account, only use stack-name.
        env:
          PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
e

echoing-dinner-19531

02/02/2024, 1:46 PM
As catememe tried to explain those separate run statements are running in separate shells. So instead of
Copy code
- run: . venv/bin/activate
      - run: which python
      - run: python --version
      - run: pip install -r requirements.txt
you need something like:
Copy code
- run: |
        . venv/bin/activate
        pip install -r requirements.txt
b

bumpy-glass-30283

02/04/2024, 2:45 PM
either that, or the Dockerfile / bash chaining syntax
Copy code
- run: python3 -m venv venv && source venv/bin/activate && which python && python --version && pip install -r requirements.txt