Skip to content
Latchkey

Python "can't open file" wrong path in CI

Python was told to run a script file that does not exist at the path given from the current working directory. CI starts in the repo root, which is often not where the script lives.

What this error means

A step fails with "python: can't open file '/home/runner/work/app/app/run.py': [Errno 2] No such file or directory" and exit code 2.

python
python: can't open file '/home/runner/work/app/app/run.py':
[Errno 2] No such file or directory
Error: Process completed with exit code 2.

Common causes

A relative path that assumes a subdirectory

The script path is relative to a subfolder the developer runs in locally, but CI runs from the repo root.

A working directory not set for the step

The step never changed into the directory holding the script, so the relative path does not resolve.

How to fix it

Set the step working directory

Pin where the step runs so the script path resolves consistently.

.github/workflows/ci.yml
- run: python run.py
  working-directory: backend

Use a path relative to the repo root

Reference the script from the checkout root so it works regardless of caller location.

Terminal
python backend/run.py

How to prevent it

  • Use paths relative to the repo root in CI commands.
  • Set working-directory explicitly for steps that need a subdir.
  • Avoid assuming the local-shell cwd in committed scripts.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →