PermissionError 🐍 Python

PermissionError: [Errno 13] Permission denied: '/path'

The OS refused the file operation — no permission, a directory passed to open(), or (on Windows) the file is open elsewhere.

Seen on: Python

Meaning

On Linux the Python process user lacks rights. On Windows, Excel or another program locking the file also raises Errno 13. Opening a directory path with open() raises it too.

Common causes

  • Process user lacks read/write permission
  • Path is a directory, not a file
  • File locked by another program (Windows)
  • Writing into a system or site-packages directory without a venv

⚡ Quick fix

  1. Check ownership/permissions with ls -l
  2. Make sure the path points to a file
  3. Close the file in other programs
  4. Use a virtual environment instead of sudo pip

Detailed fix by platform

Linux

  1. sudo chown -R $USER:$USER ./output

How to diagnose

  1. Path — File or directory?
  2. User — Which user runs Python?
  3. Lock — Open in another app?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.