123

I tried to install the Twilio module:

sudo -H pip install twilio

And I got this error:

Installing collected packages: pyOpenSSL
  Found existing installation: pyOpenSSL 0.13.1
Cannot uninstall 'pyOpenSSL'. 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.

Anyone know how to uninstall pyOpenSSL?

sophros
  • 14,672
  • 11
  • 46
  • 75
rachelvsamuel
  • 1,551
  • 2
  • 10
  • 21

6 Answers6

129

This error means that this package's metadata doesn't include a list of files that belong to it. Most probably, you have installed this package via your OS' package manager, so you need to use that rather than pip to update or remove it, too.

See e.g. Upgrading to pip 10: 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. · Issue #5247 · pypa/pip for one such example where the package was installed with apt.


Alternatively, depending on your needs, it may be more productive to not use your system Python and/or its global environment but create a private Python installation and/or environment. There are many options here including virtualenv, venv, pyenv, pipenv and installing Python from source into /usr/local or $HOME/$HOME/.local (or /opt/<whatever>).


Finally, I must comment on the often-suggested (e.g. at pip 10 and apt: how to avoid "Cannot uninstall X" errors for distutils packages) --ignore-installed pip switch.

It may work (potentially for a long enough time for your business needs), but may just as well break things on the system in unpredictable ways. One thing is sure: it makes the system's configuration unsupported and thus unmaintainable -- because you have essentially overwritten files from your distribution with some other arbitrary stuff. E.g.:

  • If the new files are binary incompatible with the old ones, other software from the distribution built to link against the originals will segfault or otherwise malfunction.
  • If the new version has a different set of files, you'll end up with a mix of old and new files which may break dependent software as well as the package itself.
  • If you change the package with your OS' package manager later, it will overwrite pip-installed files, with similarly unpredictable results.
  • If there are things like configuration files, differences in them between the versions can also lead to all sorts of breakage.
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
  • 1
    Thank you. I took your suggestion and created a private Python installation. – rachelvsamuel Dec 17 '18 at 00:20
  • 1
    What about packages installed using `sudo -H pip3 install `? I usually use that instead of building virtual env. so that my personally needed packages are installed in `/usr/local`. Hence, they should not interfere with the ones installed with `apt` in `/usr`. But even with the former command, `pip` is complaining with the error the OP mentioned. @ivan_pozdeev : would you be able to complete your already nice answer with such piece of information if you do have them? – swiss_knight Apr 29 '20 at 06:31
  • 3
    @s.k Running without `--ignore-installed` won't break stuff in the way described here. Version conflicts might happen if you install a Python package with Pip and _then_ the same package _and_ something that that depends on it with Apt. The two versions won't break each other but the dependent package might not support the newer dependency from Pip. – ivan_pozdeev Apr 29 '20 at 08:36
  • I was installed it using `yum` before. I have uninstalled by `yum remove python-requests` and then installed with `pip` by issuing `pip install requests' – SuB Nov 03 '21 at 07:39
77

I had the same error and was able to resolve using the following steps:

  pip install --ignore-installed pyOpenSSL

This will install the package with latest version and then if you try to install,

  pip install twilio

It will work.

Jennifer Therese
  • 1,105
  • 9
  • 17
  • 2
    i had the same error with 'httplib2' when trying to install 'google-api-python-client', and this solution worked for me as well (linux/ubuntu), thanks! – greenhouse Dec 04 '20 at 23:50
18

Generally, for similar errors, use this format:

pip install --ignore-installed [package name]==[package version]
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ewalel
  • 1,932
  • 20
  • 25
3

In my case, I was installing a package from internal git using the following command:

python -m pip install package.whl --force

I was doing this because I didn't want to explicitly uninstall the previous version and just replace it with a newer version. But what it also does is install all the dependencies again. I was getting the error in one of those packages. Removing --force fixed the problem.

I want to add, having --ignore-installed also worked for me. And removing --force is essentially doing the same thing in my case.

TrigonaMinima
  • 1,828
  • 1
  • 23
  • 35
2

I just had this error and the only way I was able to resolve it was by manually deleting the offending directory from site-packages.

After doing this you may need to reinstall the packages with --force-reinstall.

2

Reading the above comments, I understood that package a was installed with conda and the new package b that I was trying to install using pip was causing problems. I was lucky that package b had conda support so using conda to install package b solved the problem.

Oguz
  • 160
  • 4
  • Ran into a similar issue with trying to install `stumpy` using `pip` when conda had already installed `llvmlite`. Using conda to install stumpy fixed the issue. – KT12 Jun 30 '22 at 14:30