32

The problem:

I have installed Anaconda:

conda -V
conda 4.4.7

Also I installed a lot of packages for it using python3 setup.py install. I used it for some packages created from setup.py files.

Now I want to uninstall one package.

What I tried:

pip uninstall packageName
pip3 uninstall packageName
conda uninstall packageName

It works for python: check pip list and pip3 list and there isn't such package.

Error:

But for conda I got this:

conda uninstall packageName
Solving environment: failed

PackagesNotFoundError: The following packages are missing from the target environment:
  - packageName

Let's check:

conda list
packageName

P.S. I found info that conda uninstall and conda remove doesn't work in this case. But what to do then?

P.S.S. Actually I changed real package name at packageName but if this information is important I will add it.


My info:

conda info

     active environment : None
       user config file : /home/masamok4/.condarc
 populated config files : /home/masamok4/anaconda3/.condarc
                          /home/masamok4/.condarc
          conda version : 4.4.7
    conda-build version : 3.0.27
         python version : 3.6.3.final.0
       base environment : /home/masamok4/anaconda3  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.continuum.io/pkgs/main/linux-64
                          https://repo.continuum.io/pkgs/main/noarch
                          https://repo.continuum.io/pkgs/free/linux-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/linux-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/linux-64
                          https://repo.continuum.io/pkgs/pro/noarch
          package cache : /home/masamok4/anaconda3/pkgs
                          /home/masamok4/.conda/pkgs
       envs directories : /home/masamok4/anaconda3/envs
                          /home/masamok4/.conda/envs
               platform : linux-64
             user-agent : conda/4.4.7 requests/2.18.4 CPython/3.6.3 Linux/4.4.0-87-generic ubuntu/16.04 glibc/2.23
                UID:GID : 1003:1003
             netrc file : None
           offline mode : False
Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
  • 1
    Um... a little confusing. But `conda` and `pip` have different indexing way. `conda` use a file to record index while `pip` directly scan lib directory. So although `conda list` could show all packages including `pip install`ed. The packages installed by `pip` are out of `conda`'s control. – Sraw Jan 19 '18 at 08:56
  • @Sraw thank you for response! Ok, I get it, but how then can conda include this packages after I used `pip uninstall`? – Mikhail_Sam Jan 19 '18 at 09:25
  • Was this poblem ever solved ? – Mihaela Grigore Feb 14 '21 at 16:09
  • 1
    @Mihaela I can't say for sure - I reinstalled the entire anaconda, so I can't reproduce this behavior right now – Mikhail_Sam Feb 15 '21 at 07:23

5 Answers5

12

You can use Jupyter Notebook to solve this problem :

  • open Jupyter Notebook
  • open a new notebook with the right kernel
  • type !pip uninstall -y [package] in a code cell
  • run the cell code
xiawi
  • 1,772
  • 4
  • 19
  • 21
Loïc
  • 129
  • 1
  • 4
  • 1
    what does right kernel mean? right environment you mean? or correct python ? – agent18 Oct 01 '20 at 23:28
  • @agent18 you have to run your notebook after switching to the environment you want to modify – abe Dec 25 '20 at 14:32
  • did this work for you @xiawi ? For me it did not. – Mihaela Grigore Feb 14 '21 at 16:11
  • For the answer I proposed (not this one, on which you comment), it consists in listing all the files of the package then delete them. Thus, yes "it works" but there is a risk in terms of dependencies. If, for you, it "does not work", you should ask another question explaining the exact reasons "it does not work" (because it is not obvious at first glance) – xiawi Feb 15 '21 at 09:49
8

Definitely the best way to uninstall all pypi packages in a conda environment is:

conda activate <your-env>
conda list | awk '/pypi/ {print $1}' | xargs pip uninstall -y
1

If you installed the package using setup.py, then you will most likely have to delete the package files manually.

You'd find the Uninstalling setup.py install wiki useful. Unix instructions quoted below:

sudo python setup.py install --record files.txt
# inspect files.txt to make sure it looks ok. Then in bash:
tr '\n' '\0' < files.txt | xargs -0 sudo rm -f --
Abhinav Sood
  • 799
  • 6
  • 23
1

One has to be careful when using pip inside a conda environment, whether for installing and unistalling packages. What works for me is based on https://stackoverflow.com/a/43729857/1047213.

  1. Install pip that is specific to the conda environment by running conda install pip inside the conda environment.
  2. Specify the entire path of that specific pip while installing or uninstalling a package. Usually, you will find it inside the bin folder of the virtual environment (e.g., /anaconda/envs/venv_name/bin/). Thus, the following works for me: /anaconda/envs/venv_name/bin/pip install_or_uninstall package_name.
Hari
  • 1,561
  • 4
  • 17
  • 26
  • 1
    Thank you for the answer! I already have no such configuration, so can't check it right now But will check if face this problem again – Mikhail_Sam Nov 23 '20 at 16:03
0

As the force-remove argument of conda uninstall -h is shown,

--force-remove, --force
                        Forces removal of a package without removing packages
                        that depend on it. Using this option will usually
                        leave your environment in a broken and inconsistent
                        state.

I thank your specific package packageName is not well installed. In other words, the packages depended on by packageName are not well installed, but you want to uninstall packageName. So conda uninstall packageName failed. You can try

conda uninstall packageName --force

, whose usage is the same as the commands pip uninstall packageName and pip3 uninstall packageName. That is, "removal of a package without removing packages that depend on it".

Hope it works for you.

Libo Huang
  • 69
  • 1
  • 3