Software⏱️ 2 min read📅 2026-05-31

How to Fix: pip install failing with: OSError: [Errno 13] Permission denied on directory

Permission denied error when installing Django with pip.

Quick Answer: Check if you have write permissions for the /usr/local/lib directory. You can try running the command as root or using a different package manager like conda.

The error you're experiencing, OSError: [Errno 13] Permission denied on directory, occurs when the Python package installer, pip, doesn't have sufficient permissions to install packages in a specific directory. This is commonly seen during Django installations.

⚠️ Common Causes

  • Pip being run as a non-root user or in an environment where it lacks sufficient permissions.

🛠️ Step-by-Step Verified Fixes

Method 1: Running pip with Elevated Permissions

  1. Step 1: Open a terminal and run the command sudo pip install -r requirements.txt to elevate your permissions.

Method 2: Changing Default Installation Directory

  1. Step 1: Use the --target-dir flag when running pip. You can do this by adding --target-dir=/usr/local/lib/pythonX.X/site-packages to your pip install command, for example: pip --target-dir=/usr/local/lib/pythonX.X/site-packages install -r requirements.txt.

✨ Wrapping Up

By following these steps, you should be able to resolve the OSError: [Errno 13] Permission denied on directory issue and successfully install Django. Remember that running pip with elevated permissions or changing the default installation directory can resolve this common problem.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions