Set pythonpath in Github Actions, running on Ubuntu.

I am relying on modules in my project for which I would like to set append a PYTHONPATH.

Working locally I would do it like this and it works.

export PYTHONPATH=$PYTHONPATH:/home/<user>/<code>

However, the same approach for Github Actions throws the error:

ModuleNotFoundError: No module named 'xxxx'

my_workflow.yml

name: my_workflow

on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: set pythonpath
run: |
# this does not work.
export PYTHONPATH=$PYTHONPATH:/home/runner/work/<repo_name>
- name: Test with pytest
run: |
pip install pytest
pytest

pwd returns

/home/runner/work/<repo_name>/<repo_name>

I have tried to to set the PYTHONPATH to both 

.../work/<repo_name>

and the above, with no luck.

Please help!

Each step in actions runs in its own process so exporting in a shell is not going to translate across steps.  To update the path for a downstream step you need to use the add-path workflow command https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path.

1 Like

command: echo “::add-path::/path/to/dir” will pepend a directory to the system PATH variable for all subsequent actions in the current job. But look at your code, are you searching ‘set-env’?

echo "::set-env name=PYTHONPATH::home/runner/work/<repo_name>"
1 Like

Hello i keep having the same error. can you give me a step by set on how i solve this.