Python "FileExistsError: [Errno 17]" in CI
FileExistsError: [Errno 17] File exists is raised by os.mkdir, os.makedirs without exist_ok=True, an exclusive open ("x"), or os.symlink when the target path already exists.
What this error means
A step fails with "FileExistsError: [Errno 17] File exists: 'build/out'" when creating a directory, symlink, or exclusive file.
python
FileExistsError: [Errno 17] File exists: 'build/out'Common causes
mkdir without exist_ok on a leftover directory
A re-run or cached workspace already contains the directory, and mkdir refuses to recreate it.
An exclusive-create open on an existing file
Opening with mode "x" requires the file to not exist; a leftover artifact triggers the error.
How to fix it
Make creation idempotent
- Use
os.makedirs(path, exist_ok=True)for directories. - Remove or overwrite an existing target before an exclusive create, or use mode "w".
- Clean stale output at the start of the step in cached workspaces.
Python
import os
os.makedirs("build/out", exist_ok=True)How to prevent it
- Prefer exist_ok=True and idempotent setup steps.
- Clean build output before regenerating it.
- Be deliberate about exclusive-create modes.
Related guides
Python "IsADirectoryError: [Errno 21]" in CIFix "IsADirectoryError: [Errno 21] Is a directory" in CI - code tried to open or read a path as a file but it…
Python "NotADirectoryError: [Errno 20]" in CIFix "NotADirectoryError: [Errno 20] Not a directory" in CI - a path component that the code treated as a dire…
Python "FileNotFoundError" opening a missing path in CIFix "FileNotFoundError: [Errno 2] No such file or directory" in CI - code opened a path that does not exist o…