Reputation: 3627
I was trying to install chatterbot which has a dependency on PyYAML=3.12. In my Ubuntu machine installed PyYAML version is 3.11. So I used the following command to upgrade PyYAML:
sudo -H pip3 install --upgrade PyYAML
But it gives the following error:
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.
My pip3 version is 10.0.0.
How to resolve this?
Upvotes: 116
Views: 185368
Reputation: 3627
I found in this Github issue that pip 10 no longer uninstalls distutils packages. So I downgraded to pip 8.1.1. And now it works.
And to downgrade pip, I used the following:
sudo -H pip3 install pip==8.1.1
Upvotes: 31
Reputation: 9
The following code will help:
rm -rf /usr/lib/python3/dist-packages/yaml
rm -rf /usr/lib/python3/dist-packages/PyYAML-*
rm -rf /usr/lib/python3.8/site-packages/PyYAML-*
sudo -H pip3 install --ignore-installed PyYAML
Upvotes: 0
Reputation: 124
If --ignore-installed
is NOT the case for you, and you are running Debian/Ubuntu, then you can try following solution.
PyYAML could possibly be installed with apt
, as a dependency of another package.
To debug that:
apt list --installed | grep python
and search for any yaml
occurrence.python3-yaml
.apt-cache rdepends --installed python3-yaml
Then you can:
python3-yaml
python3-yaml
via dpkg -r --force-depends python3-yaml
and
re-install it via pip
Upvotes: 1
Reputation: 175
conda remove PyYAML
pip install chatterbot
pip install chatterbot_corpus
In this way it sloved my error while I was trying from chatterbot import chatbot
Upvotes: 5
Reputation: 701
I have had a similar issue where the PyYAML
package was installed by conda. There is another answer to use conda remove
.
Instead I have got round this issue using conda update PyYAML
, effectively using conda to update the dependency which pip is trying itself to update.
Upvotes: 3
Reputation: 151
I personnaly had PyYAML installed on anaconda, just executing 'conda remove PyYAML' and then executing my pip command worked.
Upvotes: 6
Reputation: 7839
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.
sudo rm -rf /usr/lib/python3/dist-packages/yaml
sudo rm -rf /usr/lib/python3/dist-packages/PyYAML-*
Removing folder from distutils works
Upvotes: 13
Reputation: 2442
Try using the --ignore-installed
flag:
sudo -H pip3 install --ignore-installed PyYAML
This works because to upgrade a package, pip
first uninstalls the old version, then installs the new version. It is the uninstall step that fails for distutils packages. With the --ignore-installed
flag, the uninstall step is skipped and the new version is simply installed on top of the old one.
Upvotes: 198