Common causes
- Trying to write to a system directory (like /etc or C:\Windows) without administrator rights
- The file is owned by root or another user and your account can't write to it
- Attempting to overwrite a read-only file
- On Windows, the file is locked by another process or protected by UAC
How to fix it
- Check file permissions: ls -la <file> (Mac/Linux) or right-click → Properties (Windows)
- Change ownership or permissions: sudo chown $(whoami) <file> or chmod 644 <file>
- Write to a directory you own, like your home directory or /tmp
- On Windows, run your terminal as Administrator if you genuinely need access to that location
Example
Traceback (most recent call last):
File "app.py", line 3, in <module>
with open('/etc/hosts', 'w') as f:
PermissionError: [Errno 13] Permission denied: '/etc/hosts'Trying to write to /etc/hosts without root privileges
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
