pip cannot uninstall. It is a distutils installed project

pip cannot uninstall. It is a distutils installed project is a common error which occurs when you have a faulty package metadata.

In this post we will try to solve your error and see why it occurs in the first place, we will present multiple solutions so you can find the one which better suits your particular situation.

Explaining the Error : pip cannot uninstall . It is a distutils installed project

pip cannot uninstall… is a very common error which can be hard or easy to solve depending on how messy your situation is.

Here is an example of the error message.

                                                                       #
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
                                                                       #

‘PyYAML’ could be any other package depending on your case. ‘pyOpenSSL’ is a very common one, which happens after you try installing ‘twilio’ using pip.

Bellow I make my best attempt at solving the error and present multiple possible solutions.

Solution 1 : Solving the error by installing the package the right way

Before we try solving the error we must understand it, this error happens when the package’s metadata doesn’t contain a list of files that should be there.

In most cases, this happens when you install the package via your OS and not via pip and python, which means if you want to edit or upgrade it for example using pip it is going to give you an error similar to the error above.

So the solution is to either remove the faulty package and install it but this time install it by using pip.

Or, you can use virtualenv or pyenv. Another solution is to ignore the faulty package, we will talk about that fix in the solution bellow.

To delete the faulty package you can navigate to site-packages and manually remove it.

You can also to force reinstall the package with pip, for example you can do.

                                                                       #
pip install --upgrade --force-reinstall <package>
                                                                       #

Replace package, for example for pyOpenSSL you can do.

                                                                       #
pip install --upgrade --force-reinstall pyOpenSSL
                                                                       #

Congratulations, everything should work as intended, if that is not the case please do not give up we have another solution bellow.

Solution 2 : ignoring the faulty package

Another solution is to just ignore the faulty package, this solution is as straightforward as it gets.

This is a very popular fix for twilio. You can ignore the existing faulty pyOpenSSL installation by using the command bellow, which is awesome.

                                                                       #
pip install --ignore-installed pyOpenSSL
                                                                       #

Now that we have the right package with right files, we can just install Twilio using pip by using the command bellow.

                                                                       #
pip install twilio
                                                                       #

The error above was hard to deal with, I spent hours looking for a proper solution or set of solutions, I hope the two fixes have been helpful.

Summing-up

That’s it fellow developers, this is the end of this guide, I hope you found this useful in solving your particular issue, if you have the means and want to help, please support our work on our Kofi account, you do not have to, but you can donate if you want.

Thank you, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/