FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
Most likely cause: The config.json file is missing or was never created in the expected folder
Try first: Check if the file exists in the current folder (ls (macOS/Linux) or dir (Windows))
Likely causes
- The config.json file is missing or was never created in the expected foldermost likely
- The program is looking in the wrong folder because the working directory is different from where the file actually ispossible
- A typo in the filename or path inside the codeless likely
How to fix it
Check if the file exists in the current folderSafe
Open a terminal or command prompt in the same folder as your script and list the files to see if config.json is present.
ls (macOS/Linux) or dir (Windows)Print the current working directory from your codeSafe
Add a line to print the folder the program thinks it is in so you can compare it to where the file actually lives.
import os; print(os.getcwd())Create an empty config.json if it is missingChanges settings
If the file should exist but does not, create a blank one so the program can at least start, then add the needed settings later.
touch config.json (macOS/Linux) or echo. > config.json (Windows)
If that didn't fix it
Add code that checks whether config.json exists before trying to open it and prints the full path it is attempting to use
When to see a technician
Contact the developer or someone familiar with the code if you cannot locate or create the missing config file.
Quick answers
- What does FileNotFoundError: [Errno 2] No such file or directory: 'config.json' mean?
- This Python error happens when code tries to open or read a file named config.json but the file does not exist in the folder the program is running from.
- What causes FileNotFoundError: [Errno 2] No such file or directory: 'config.json'?
- The config.json file is missing or was never created in the expected folder. (most likely) The program is looking in the wrong folder because the working directory is different from where the file actually is. (possible) A typo in the filename or path inside the code. (less likely)
- How do I fix FileNotFoundError: [Errno 2] No such file or directory: 'config.json'?
- Try these in order, safest first: 1. Check if the file exists in the current folder. 2. Print the current working directory from your code. 3. Create an empty config.json if it is missing.
- What if that didn't fix it?
- Add code that checks whether config.json exists before trying to open it and prints the full path it is attempting to use
- When should I see a technician?
- Contact the developer or someone familiar with the code if you cannot locate or create the missing config file.