Last updated: Apr 9, 2024
Reading timeยท3 min
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.
six
packageOne 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.
pip install --ignore-installed six pip3 install --ignore-installed six
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.
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.
--user
optionThe 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.
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.
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
.
sudo pip install <package-name> sudo pip3 install <package-name> sudo python -m pip install <package-name> sudo python3 -m pip install <package-name>
If that didn't help, try creating a virtual environment.
pip install
command with the virtual environment active.# ๐๏ธ 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.
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
.
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
.
Here are the commands for upgrading pip
on all operating systems.
Which command works depends on your operating system and your version of Python.
# ๐๏ธ 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
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.
pip install --upgrade setuptools pip3 install --upgrade setuptools python3 -m pip install --upgrade setuptools
Try to run the pip install
command now that pip
and setuptools
are
upgraded.
If none of the suggestions helped, try reinstalling Python.
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.