Search code examples
pythonpipanacondacondapackage-management

Packages don't match when conda uninstall and install


There has been an ImportError when opening jupyter notebook so I followed here and ran conda uninstall pyzmq -> conda install pyzmq.

I used conda instead of pip since people say "Don't mix up conda and pip commands under conda environment".

Then I came to realise that packages for conda uninstall pyzmq and conda install pyzmq are different:

  • conda uninstall pyzmq ; 19 packages REMOVED
  • conda install pyzmq ; only 3 packages INSTALLED

Why do packages installed and uninstalled via same conda command differ?
Shouldn't they install and reinstall exactly corresponding packages?

I am still pretty new to Anaconda, if you have any tricks for a better conda envs management to minimize the risk of broken envs, your advise is greatly appreciated.


when conda uninstall

(my_env) C:\Users\koyamashinji>conda uninstall pyzmq
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##
  environment location: C:\Users\koyamashinji\anaconda3\envs\my_env
  removed specs:
    - pyzmq

The following packages will be REMOVED:

  colorama-0.4.4-py_0
  decorator-4.4.2-py_0
  ipykernel-5.3.4-py36h5ca1d4c_0
  ipython-5.8.0-py36_1
  ipython_genutils-0.2.0-pyhd3eb1b0_1
  jupyter_client-6.1.7-py_0
  jupyter_core-4.7.0-py36haa95532_0
  libsodium-1.0.18-h62dcd97_0
  pickleshare-0.7.5-pyhd3eb1b0_1003
  prompt_toolkit-1.0.15-py_1
  pygments-2.7.2-pyhd3eb1b0_0
  python-dateutil-2.8.1-py_0
  pywin32-227-py36he774522_1
  pyzmq-20.0.0-py36hd77b12b_1
  simplegeneric-0.8.1-py36_2
  tornado-6.1-py36h2bbff1b_0
  traitlets-4.3.3-py36_0
  wcwidth-0.2.5-py_0
  zeromq-4.3.3-ha925a31_3

when conda install

(my_env) C:\Users\koyamashinji>conda install pyzmq
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\koyamashinji\anaconda3\envs\my_env

  added / updated specs:
    - pyzmq


The following NEW packages will be INSTALLED:

  libsodium          pkgs/main/win-64::libsodium-1.0.18-h62dcd97_0
  pyzmq              pkgs/main/win-64::pyzmq-20.0.0-py36hd77b12b_1
  zeromq             pkgs/main/win-64::zeromq-4.3.3-ha925a31_3

Solution

  • Why do packages installed and uninstalled via same conda command differ? Shouldn't they install and reinstall exactly corresponding packages?

    conda install and conda uninstall should install and uninstall exactly corresponding packages, as long as the environment is not already broken.
    My environment was already broken probably because I used pip to install a few jupyter-related packages before (as you can see some packages are py_0 which means they were installed via pip install.)


    I am still pretty new to Anaconda, if you have any tricks for a better conda envs management to minimize the risk of broken envs, your advise is greatly appreciated.

    I spent my whole week trying to figure out how they work, and here's what I got (for now).

    • Make sure you specify python version supported by Anaconda at environment creation.
      Check here and specify python version when conda create -n my_env python==version.

    • Make sure you also install all known required packages at environment creation.
      conda create -n my_env python=version package_A, package_B ...
      As Official document says "Install all the programs that you want in this environment at the same time. Installing 1 program at a time can lead to dependency conflicts."

    • Make sure you understand exactly what conda install/uninstall and pip install/uninstall do.

    conda install/uninstall

    (my_env) C:\Users> conda install package_A  
    
    # Installs : package_A + dependencies(dependency_1, dependency_2, dependency_3)
      
    
    (my_env) C:\Users> conda uninstall package_A
    
    # Uninstalls : package_A + dependencies(dependency_1, dependency_2, dependency_3)
    
    (my_env) C:\Users> conda install package_A
    
    # Installs : package_A + dependencies(dependency_1, dependency_2, dependency_3)    
      
    
    (my_env) C:\Users> conda uninstall dependency_1
    
    # Uninstalls : package_A + dependencies(dependency_1, dependency_2, dependency_3)
    

    pip install/uninstall

    (my_env) C:\Users> pip install package_A  
    
    # Installs : package_A + dependencies(dependency_1, dependency_2, dependency_3)
      
    
    (my_env) C:\Users> pip uninstall package_A
    
    # Uninstalls : package_A ONLY
    
    (my_env) C:\Users> pip install package_A
    
    # Installs : package_A + dependencies(dependency_1, dependency_2, dependency_3)    
      
    
    (my_env) C:\Users> pip uninstall dependency_1
    
    # Uninstalls : dependency_1 ONLY