Pip cannot uninstall <package> error in Python [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 9, 2024
12 min

banner

# Table of Contents

  1. Pip cannot uninstall package error in Python
  2. Cannot uninstall 'PyYAML' error in Python
  3. Cannot uninstall 'llvmlite' in Python
  4. Cannot uninstall 'certifi' in Python
  5. Cannot uninstall 'numpy' error in Python
  6. Cannot uninstall 'wrapt' in Python

# Pip cannot uninstall package error in Python

The Python error "Cannot uninstall [package]" occurs when we install a package with the operating system's package manager and try to update or remove the package using pip.

To solve the error, use the --ignore-installed option, e.g. pip install --ignore-installed <package-name>.

shell
Installing collected packages:<package-name> Found existing installation:<package-name> Cannot uninstall <package-name>. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

The error often occurs when uninstalling PyYAML, llvmlite, numpy, certifi or wrapt.

To solve the error, run the pip install command with the --ignore-installed option.

Make sure to replace requests with the package from your error message.

shell
pip install --ignore-installed requests pip3 install --ignore-installed requests # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install --ignore-installed requests python3 -m pip install --ignore-installed requests # ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip install --ignore-installed requests sudo pip3 install --ignore-installed requests

pip install with ignore installed flag

If you were trying to install another package that depends on requests, install it after running the pip install --ignore-installed requests command.

If you were trying to remove a specific package, run the following command.

shell
sudo apt-get remove python-requests pip uninstall requests pip3 uninstall requests
The --ignore-installed option ignores the installed packages and overwrites them.

This helps because the most common cause of the error is installing a module with the operating system's package manager (or Anaconda) and trying to update or remove the package using pip.

The --ignore-installed option ignores the installed package and overwrites it.

# Deactivate your virtual environment before installing the package

If the suggestion didn't help and you are inside a virtual environment, try deactivating it first.

shell
# ๐Ÿ‘‡๏ธ Deactivate virtual environment deactivate # ๐Ÿ‘‡๏ธ Install the package from your error message pip install --ignore-installed requests pip3 install --ignore-installed requests python -m pip install --ignore-installed requests python3 -m pip install --ignore-installed requests sudo pip install --ignore-installed requests sudo pip3 install --ignore-installed requests # ๐Ÿ‘‡๏ธ Activate virtual env on Unix or macOS source venv/bin/activate # ๐Ÿ‘‡๏ธ Activate virtual env on Windows (cmd.exe) venv\Scripts\activate.bat # ๐Ÿ‘‡๏ธ Activate virtual env on Windows (PowerShell) venv\Scripts\Activate.ps1

deactivate venv before installing

Make sure to replace requests with the package from your error message.

# Try using the conda update if you used Anaconda to install the package

If you used Anaconda to install the package and are trying to update it using pip, use the conda update command.

shell
conda update requests

conda update requests

If the package was installed using Anaconda, you will be able to update it using the conda update command.

Another thing you might try is to use the conda remove command.

shell
conda remove requests

Once the package is removed using conda remove, you can use the pip install command to install it.

You can also try running the conda update --all command before installing the package.

shell
conda update --all

# Try installing the package in a virtual environment

If the error is not resolved and you aren't in a virtual environment, try creating one.

  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 # ๐Ÿ‘‡๏ธ Upgrade pip pip install --upgrade pip # ๐Ÿ‘‡๏ธ install requests in a virtual environment pip install requests

If the python3 -m venv venv command doesn't work, try one of the following 2 commands:

  • python -m venv venv
  • py -m venv venv

Make sure to use the correct activation command depending on your operating system.

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

Creating a virtual environment and installing the package inside it helps because the virtual environment is an isolated Python installation.

# Examples of solving the error for specific packages

Here are some examples of how to solve the error for specific packages.

# Table of Contents

  1. Cannot uninstall 'PyYAML' error in Python
  2. Cannot uninstall 'llvmlite' in Python
  3. Cannot uninstall 'certifi' in Python
  4. Cannot uninstall 'numpy' error in Python
  5. Cannot uninstall 'wrapt' in Python

# Cannot uninstall 'PyYAML' error in Python

The error "Cannot uninstall 'PyYAML'" occurs when we install the PyYAML package with the operating system's package manager and try to update or remove the package using pip.

To solve the error, use the --ignore-installed option, e.g. pip install --ignore-installed PyYAML.

shell
Installing collected packages: PyYAML Found existing installation: PyYAML Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

To solve the error, run the pip install command with the --ignore-installed option.

shell
pip install --ignore-installed PyYAML pip3 install --ignore-installed PyYAML # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install --ignore-installed PyYAML python3 -m pip install --ignore-installed PyYAML # ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip install --ignore-installed PyYAML sudo pip3 install --ignore-installed PyYAML
The --ignore-installed option ignores the installed packages and overwrites them.

This helps because the most common cause of the error is installing the PyYAML module with the operating system's package manager (or Anaconda) and trying to update or remove the package using pip.

The --ignore-installed option ignores the installed PyYAML package and overwrites it.

If you used Anaconda to install PyYAML and are trying to update it using pip, use the conda update command instead.

shell
conda update PyYAML

If the package was installed using Anaconda, you will be able to update it using the conda update command.

Another thing you might try is to use the conda remove PyYAML command, but that might not be a good idea because other packages in your environment might depend on PyYAML, which means that you would have to reinstall them as well.

# Try installing the package in a virtual environment

If the error is not resolved and you aren't in a virtual environment, try creating one.

  1. Create a virtual environment.
  2. Activate the virtual environment.
  3. Run the pip install PyYAML 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 # ๐Ÿ‘‡๏ธ Upgrade pip pip install --upgrade pip # ๐Ÿ‘‡๏ธ Install PyYAML in your virtual environment pip install PyYAML

Make sure to use the correct activation command depending on your operating system.

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

Creating a virtual environment and installing PyYAML inside of it helps because the virtual environment is an isolated Python installation.

# ERROR: Cannot uninstall 'llvmlite' in Python

The error "Cannot uninstall 'llvmlite'" occurs when we install a package that depends on llvmlite with the operating system's package manager and try to update or remove the package using pip.

To solve the error, use the --ignore-installed option, e.g. pip install --ignore-installed llvmlite.

shell
ERROR: Cannot uninstall 'llvmlite'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

To solve the error, run the pip install command with the --ignore-installed option.

shell
pip install --ignore-installed llvmlite pip3 install --ignore-installed llvmlite # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install --ignore-installed llvmlite python3 -m pip install --ignore-installed llvmlite # ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip install --ignore-installed llvmlite sudo pip3 install --ignore-installed llvmlite

After you install the llvmlite package, you can run the pip install command to install the package you initially tried to install, e.g. nemo_toolkit.

shell
pip install "nemo_toolkit[all]"
The --ignore-installed option ignores the installed packages and overwrites them.

This helps because the most common cause of the error is installing a package that depends on the llvmlite module with the operating system's package manager (or Anaconda) and trying to update or remove the package using pip.

The --ignore-installed option ignores the installed llvmlite package and overwrites it.

If you used Anaconda to install the package and are trying to update it using pip, use the conda update llvmlite command first.

shell
conda update llvmlite pip install "nemo_toolkit[all]"

If the package was installed using Anaconda, you will be able to update it using the conda update command.

Another thing you might try is to use the conda remove llvmlite command before installing the package.

shell
conda remove llvmlite pip install "nemo_toolkit[all]"

# Try installing the package in a virtual environment

If the error is not resolved and you aren't in a virtual environment, try creating one.

  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 # ๐Ÿ‘‡๏ธ Upgrade pip pip install --upgrade pip # ๐Ÿ‘‡๏ธ install the package in the virtual environment pip install "nemo_toolkit[all]"

Make sure to use the correct activation command depending on your operating system.

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

Creating a virtual environment and installing the package inside it helps because the virtual environment is an isolated Python installation.

# ERROR: Cannot uninstall 'certifi' in Python

The error "Cannot uninstall 'certifi'" occurs when we install a package that depends on certifi with the operating system's package manager and try to update or remove the package using pip.

To solve the error, use the --ignore-installed option, e.g. pip install --ignore-installed certifi.

shell
ERROR: Cannot uninstall 'certifi'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

To solve the error, run the pip install command with the --ignore-installed option.

shell
pip install --ignore-installed certifi pip3 install --ignore-installed certifi # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install --ignore-installed certifi python3 -m pip install --ignore-installed certifi # ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip install --ignore-installed certifi sudo pip3 install --ignore-installed certifi

After you install the certifi package, you can run the pip install command to install the package you initially tried to install.

The --ignore-installed option ignores the installed packages and overwrites them.

This helps because the most common cause of the error is installing a package that depends on the certifi module with the operating system's package manager (or Anaconda) and trying to update or remove the package using pip.

The --ignore-installed option ignores the installed certifi package and overwrites it.

If you used Anaconda to install the package and are trying to update it using pip, use the conda update certifi command first.

shell
conda update certifi # ๐Ÿ‘‡๏ธ Install the other package that depends on certifi pip install requests

If the package was installed using Anaconda, you will be able to update it using the conda update command.

Another thing you might try is to use the conda remove certifi command before installing the package.

shell
conda remove certifi # ๐Ÿ‘‡๏ธ install the other package that depends on certifi pip install requests

# Try installing the package in a virtual environment

If the error is not resolved and you aren't in a virtual environment, try creating one.

  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 # ๐Ÿ‘‡๏ธ Upgrade pip pip install --upgrade pip # ๐Ÿ‘‡๏ธ Install the package in the virtual environment pip install requests

Make sure to use the correct activation command depending on your operating system.

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

Creating a virtual environment and installing the package inside it helps because the virtual environment is an isolated Python installation.

# Cannot uninstall 'numpy' error in Python

The error "Cannot uninstall 'numpy'" occurs when we install the numpy package with the operating system's package manager and try to update or remove the package using pip.

To solve the error, use the --ignore-installed option, e.g. pip install --ignore-installed numpy.

shell
Installing collected packages: numpy Found existing installation: numpy Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

To solve the error, run the pip install command with the --ignore-installed option.

shell
pip install --ignore-installed numpy pip3 install --ignore-installed numpy # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install --ignore-installed numpy python3 -m pip install --ignore-installed numpy # ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip install --ignore-installed numpy sudo pip3 install --ignore-installed numpy

If you were trying to install another package that depends on numpy, install it after running the pip install --ignore-installed numpy command.

If you were trying to remove numpy, run the following command.

shell
sudo apt-get remove python-numpy pip uninstall numpy pip3 uninstall numpy
The --ignore-installed option ignores the installed packages and overwrites them.

This helps because the most common cause of the error is installing the numpy module with the operating system's package manager (or Anaconda) and trying to update or remove the package using pip.

The --ignore-installed option ignores the installed numpy package and overwrites it.

If you used Anaconda to install numpy and are trying to update it using pip, use the conda update numpy command.

shell
conda update numpy

If the package was installed using Anaconda, you will be able to update it using the conda update command.

Another thing you might try is to use the conda remove numpy command.

shell
conda remove numpy

Once the package is removed using conda remove, you can use the pip install command to install it.

# Try installing the package in a virtual environment

If the error is not resolved and you aren't in a virtual environment, try creating one.

  1. Create a virtual environment.
  2. Activate the virtual environment.
  3. Run the pip install numpy 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 # ๐Ÿ‘‡๏ธ Upgrade pip pip install --upgrade pip # ๐Ÿ‘‡๏ธ Install numpy in your virtual environment pip install numpy

Make sure to use the correct activation command depending on your operating system.

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

Creating a virtual environment and installing numpy inside of it helps because the virtual environment is an isolated Python installation.

# ERROR: Cannot uninstall 'wrapt' in Python

The error "Cannot uninstall 'wrapt'" occurs when we install the tensorflow package with the operating system's package manager and try to update or remove the package using pip.

To solve the error, use the --ignore-installed option, e.g. pip install --ignore-installed wrapt.

shell
Installing collected packages: wrapt, tensorflow Found existing installation: wrapt ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

To solve the error, run the pip install command with the --ignore-installed option.

shell
pip install --ignore-installed wrapt pip install tensorflow pip3 install --ignore-installed wrapt pip3 install tensorflow # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install --ignore-installed wrapt python -m pip install tensorflow python3 -m pip install --ignore-installed wrapt python3 -m pip install tensorflow # ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip install --ignore-installed wrapt sudo pip install tensorflow sudo pip3 install --ignore-installed wrapt sudo pip3 install tensorflow
The --ignore-installed option ignores the installed packages and overwrites them.

This helps because the most common cause of the error is installing the tensorflow module with the operating system's package manager (or Anaconda) and trying to update or remove the package using pip.

The --ignore-installed option ignores the installed wrapt package and overwrites it.

If you used Anaconda to install tensorflow and are trying to update it using pip, use the conda update wrapt command first.

shell
conda update wrapt pip install tensorflow

If the package was installed using Anaconda, you will be able to update it using the conda update command.

Another thing you might try is to use the conda remove wrapt command before installing tensorflow.

shell
conda remove wrapt pip install tensorflow

# Try installing the package in a virtual environment

If the error is not resolved and you aren't in a virtual environment, try creating one.

  1. Create a virtual environment.
  2. Activate the virtual environment.
  3. Run the pip install tensorflow 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 # ๐Ÿ‘‡๏ธ Upgrade pip pip install --upgrade pip # ๐Ÿ‘‡๏ธ Install tensorflow in your virtual environment pip install tensorflow

Make sure to use the correct activation command depending on your operating system.

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

Creating a virtual environment and installing tensorflow inside it helps because the virtual environment is an isolated Python installation.

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