Skip to content

FileNotFoundError: [Errno 2] No such file or directory - Why can't Python find my file? #1

@go2maxi

Description

@go2maxi

I have a file in the 'data' folder, but when I run my script, Python says it doesn't exist.

I'm using:
open('./data/config.json')

How do I fix this relative path issue?

Solution I found:
Using an absolute path based on the script location solved it.

Full example with terminal log:
https://github.com/go2maxi/common-python-errors/tree/main/os-filenotfounderror-wrong-relative-path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions