Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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