Skip to main content

How to Solve "OSError: [Errno 1] Operation not permitted" during pip install

The OSError: [Errno 1] Operation not permitted error (or similar messages like "Permission denied") during a pip install operation indicates that the user running the command lacks the necessary permissions to install packages into the target directory.

This is extremely common, especially on macOS and Linux systems, and is almost never a bug in the package you're trying to install.

This guide explains the underlying causes and provides the correct, safe solutions.

Understanding the Error: Permissions

Python packages are typically installed into system-wide directories (e.g., /usr/local/lib/python3.x/site-packages on Linux/macOS, or C:\Program Files\PythonXX\Lib\site-packages on Windows).

Modifying these directories usually requires administrator or root privileges.

The Operation not permitted error means you're trying to install a package into a location where your current user account doesn't have write access.

Solutions

If you are not using a virtual environment (which you should be!), the best solution is to install the package into your user's home directory using the --user flag:

pip install <package-name> --user
# OR, for Python 3 (might be pip3, pip3.10, etc.)
pip3 install <package-name> --user

# OR, if pip is not in your PATH
python -m pip install <package-name> --user
python3 -m pip install <package-name> --user
  • What it does: The --user flag tells pip to install the package into a user-specific directory (e.g., ~/.local/lib/python3.x/site-packages on Linux/macOS, or a similar location on Windows). You don't need administrator privileges to write to your own home directory.
  • Why it's good: This avoids modifying system-wide Python installations, which can lead to conflicts and instability. It's a good compromise if you're not using virtual environments (though virtual environments are still strongly preferred).

Using Virtual Environments (Best Practice!)**

The absolute best practice is to use virtual environments for all your Python projects. Virtual environments create isolated spaces for your projects, so you can install packages without affecting your system-wide Python installation or other projects.

  1. Create a virtual environment:

    python3 -m venv venv  # Recommended: Use built-in 'venv' module
    # OR (if the above fails)
    python -m venv venv
    # OR (Windows)
    py -m venv venv

    This creates a directory named venv (you can use any name) containing a self-contained Python installation.

  2. Activate the environment:

    • Linux/macOS (bash/zsh):

      source venv/bin/activate
    • Windows (Command Prompt):

      venv\Scripts\activate.bat
    • Windows (PowerShell):

      venv\Scripts\Activate.ps1

      If you encounter a PowerShell execution policy error, you may need to (temporarily) allow script execution: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser (Run as Administrator if needed).

  3. Install packages within the activated environment:

    pip install <package-name>  # No --user needed!

    When the environment is active, pip (and python) will automatically refer to the environment's versions, and packages will be installed into the environment's site-packages directory (e.g., venv/lib/python3.x/site-packages). You have full permissions within this environment.

sudo (Strongly Discouraged, and Why)

You might be tempted to use sudo pip install ... (on Linux/macOS) to force the installation. This is strongly discouraged and can break your system Python installation.

Why sudo pip is dangerous:

  • System Instability: System tools and utilities often rely on specific versions of Python packages. Using sudo pip can overwrite these system-installed packages, leading to breakage.
  • Dependency Conflicts: You can easily create conflicts between system packages and the packages you install with sudo pip.
  • Security Risks: Running pip with sudo gives the installation script root access to your system. A malicious or buggy package could cause significant damage.
note

Use --user or virtual environments instead.

Fixing six Issues on macOS (Specific Case)

On some older macOS versions, there can be conflicts with the pre-installed six package. If you specifically see errors mentioning six, you can try:

pip install --upgrade --ignore-installed six <package-name>
# OR, for Python 3
pip3 install --upgrade --ignore-installed six <package-name>

This command tells pip to ignore the existing six installation and install the required version. This is a specific workaround for a specific issue on some macOS systems. It's not a general solution.

Conclusion

The OSError: [Errno 1] Operation not permitted during pip install is almost always a permissions issue.

The best solution is to use virtual environments.

  • If you're not using a virtual environment, use the --user flag.
  • Never use sudo pip install unless you absolutely know what you're doing and are prepared for the potential consequences.
  • The --ignore-installed six flag can sometimes resolve a specific issue on macOS related to the six package.

By following these guidelines, you'll install Python packages safely and avoid system-wide problems.