OSError: [Error 1] Operation not permitted - pip install

avatar
Borislav Hadzhiev

Last updated: Apr 9, 2024
3 min

banner

# OSError: [Error 1] Operation not permitted - pip install

The "OSError: [Error 1] Operation not permitted" error is often caused by having incompatible versions of packages on a macOS machine.

To solve the error, run the pip install --ignore-installed six command and rerun the installation command.

# Upgrade your version of the six package

One way to solve the error is to upgrade the version of your six package, which other packages depend on and rerun your pip install command.

shell
pip install --ignore-installed six pip3 install --ignore-installed six

upgrade six version

This is necessary because some operating systems ship with an older version of six than is required by other packages.

You can also try to install the specific package and upgrade six in the same command.

shell
pip install <package-name> --upgrade --ignore-installed six pip3 install <package-name> --upgrade --ignore-installed six sudo pip install <package-name> --upgrade --ignore-installed six sudo pip3 install <package-name> --upgrade --ignore-installed six

Make sure to replace the <package-name> placeholder with the actual name of the package you are trying to install.

If that didn't help, try running the pip install command with the --user option.

# Run pip install with the --user option

The error also occurs when we don't have the necessary permissions to install a package.

One way to solve the error is to run the pip install command with the --user option.

shell
pip install <package-name> --user pip3 install <package-name> --user python -m pip install <package-name> --user python3 -m pip install <package-name> --user

Make sure to replace the <package-name> placeholder with the actual name of the package, e.g. pip install numpy --user.

The --user option installs the package in the user's home directory.

The command basically installs the package scoped to the specific user, not for the entire system. This helps with permission issues.

However, the --user option wouldn't work if you have a virtual environment active.

Another thing you could try is to elevate your permissions using sudo.

shell
sudo pip install <package-name> sudo pip3 install <package-name> sudo python -m pip install <package-name> sudo python3 -m pip install <package-name>

# Create a virtual environment

If that didn't help, try creating a virtual environment.

  1. Create a virtual environment.
  2. Activate the virtual environment.
  3. Run the pip install command with the virtual environment active.
shell
# ๐Ÿ‘‡๏ธ Use the correct version of Python when creating VENV python3 -m venv venv # ๐Ÿ‘‡๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐Ÿ‘‡๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐Ÿ‘‡๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # ๐Ÿ‘‡๏ธ Install the specific package in the virtual environment pip install numpy

Make sure to use the correct command to activate your virtual environment depending on your operating system and your shell.

Your virtual environment will use the version of Python that was used to create it.

Make sure to not create your virtual environment as root, e.g. with sudo because then you'd only permit root users to install packages.

If you created your virtual environment using sudo, try changing its permissions or recreate it without sudo.

shell
sudo chmod -R 777 venv

The command above assumes that your virtual environment is in a folder called venv.

777 means granting all users full access to the contents of the directory.

If that didn't help, try upgrading pip.

# Upgrade your version of pip

Here are the commands for upgrading pip on all operating systems.

Which command works depends on your operating system and your version of Python.

shell
# ๐Ÿ‘‡๏ธ If you have pip already installed pip install --upgrade pip # ๐Ÿ‘‡๏ธ If your pip is aliased as pip3 (Python 3) pip3 install --upgrade pip # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install --upgrade pip # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python3 -m pip install --upgrade pip

upgrade pip version

If you get the error ModuleNotFoundError: No module named 'pip', click on the link and follow the instructions.

If the commands from the code sample didn't work for you, click on the "Install pip in Python" link.

After you upgrade pip, upgrade setuptools as well.

shell
pip install --upgrade setuptools pip3 install --upgrade setuptools python3 -m pip install --upgrade setuptools

upgrade setuptools version

Try to run the pip install command now that pip and setuptools are upgraded.

# Reinstall Python on your machine

If none of the suggestions helped, try reinstalling Python.

shell
brew install python

Running the brew install python command sometimes helps because the installation comes with updated versions for some of the packages that cause the issue.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev