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: 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.
- run: python run.py
working-directory: backendUse a path relative to the repo root
Reference the script from the checkout root so it works regardless of caller location.
python backend/run.pyHow to prevent it
- Use paths relative to the repo root in CI commands.
- Set
working-directoryexplicitly for steps that need a subdir. - Avoid assuming the local-shell cwd in committed scripts.