Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anaconda: How to safely remove duplicate packages

I have an Anaconda virtual environment in which I have a lot of Python packages installed multiple times, often in different versions, for example:

$ conda list
...
singledispatch            3.4.0.3                  py35_0  
sip                       4.18                     py35_0  
six                       1.10.0                    <pip>
six                       1.11.0                    <pip>
six                       1.10.0                   py35_0  
snowballstemmer           1.2.1                    py35_0  
sockjs-tornado            1.0.3                    py35_0  
sphinx                    1.5.4                    py35_0  
spyder                    3.1.3                    py35_0  
sqlalchemy                1.1.9                    py35_0  
sqlite                    3.13.0                        0  
statsmodels               0.8.0               np111py35_0  
sympy                     1.0                      py35_0  
tensorflow-gpu            1.3.0                     <pip>
tensorflow-gpu            1.0.1                     <pip>
tensorflow-tensorboard    0.1.6                     <pip>
terminado                 0.6                      py35_0  
testpath                  0.3                      py35_0  
Theano                    0.9.0                     <pip>
tk                        8.5.18                        0  
toolz                     0.8.2                    py35_0  
tornado                   4.4.2                    py35_0  
tqdm                      4.11.2                    <pip>
tqdm                      4.15.0                   py35_0  
traitlets                 4.3.2                    py35_0  
unicodecsv                0.14.1                   py35_0  
wcwidth                   0.1.7                    py35_0  
werkzeug                  0.12.1                   py35_0  
Werkzeug                  0.12.2                    <pip>
wheel                     0.29.0                    <pip>
wheel                     0.30.0                    <pip>
wheel                     0.29.0                   py35_0  
...

I don't know how I got to this state, but how can I safely get rid of the duplicate packages?

Also, if a program imports the six package, how does Python determine which version to import?

EDIT: I know now where the problem came from. I probably installed some packages using pip's --ignore-installed option. Am I fine with all the duplicates being installed like this or should I get rid of them?

like image 965
Alex Avatar asked Jan 11 '18 15:01

Alex


2 Answers

If you don't need specific version of any one of those, then I would try conda update conda which should remove all the old packages, install the newest versions, and set the newest versions as default. Otherwise, you can always use conda remove <pkg-name> to remove all the copies and conda install <pkg-name> to install the latest version and replace the old ones. You can also use pip install <pkg-name>==<version> to install a specific version (for example, pip install keras==1.2). This link is also helpful.

like image 74
Mehdi Avatar answered Sep 23 '22 09:09

Mehdi


For begginers, this tutorial might be useful

conda clean --all

https://youtu.be/GNd_em2IzW4

like image 26
SciPy Avatar answered Sep 22 '22 09:09

SciPy