33

I installed PyTorch with:

conda install pytorch torchvision cuda80 -c soumith

How do I uninstall and remove all PyTorch dependencies?

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
vincent
  • 1,558
  • 4
  • 21
  • 34

6 Answers6

53

From the anaconda docs, you can uninstall with conda uninstall

Try

conda uninstall pytorch torchvision cuda80 -c soumith

Alternatively, the pytorch docs suggest

conda uninstall pytorch
pip uninstall torch
pip uninstall torch # run this command twice
wpercy
  • 9,636
  • 4
  • 33
  • 45
  • This does not remove all the files. – Schütze Mar 26 '18 at 12:30
  • 1
    Hey @Schütze Could you please elaborate a bit more on this issue. – Shagun Sodhani Oct 01 '18 at 15:24
  • I also uninstalled pytorch like this, but then I got the error "ImportError: DLL load failed: The specified module could not be found". The solution to that again was https://stackoverflow.com/questions/44537131/numpy-library-importerror-dll-load-failed-the-specified-procedure-could-not-be and there the answer of @User1024, by adding a Path variable. p.s.: I have not done anything else than uninstalling pytorch, that is why I think this is a relevant post to this topic, though it does not directly answer the question. – questionto42 May 20 '20 at 19:58
14

Here's the correct set of commands according to CONTRIBUTING.md from the pytorch github repo:


Uninstall all existing pytorch installs

conda uninstall pytorch
pip uninstall torch
pip uninstall torch # run this command twice
190290000 Ruble Man
  • 2,173
  • 1
  • 20
  • 25
  • I had to use pip uninstall since I had installed a Wheel with pip. The uninstall works, but it also threw an error: ` Successfully uninstalled torch-1.5.1+cu92 ERROR: Exception: Traceback (most recent call last): File "C:\Users\Admin\anaconda3\envs\ml\lib\site-packages\pip\_internal\cli\base_command.py", line 216, in _main status = self.run(options, args)` ... `PermissionError: [WinError 5] Zugriff verweigert: 'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-uninstall-dtsa8at_\\lib\\c10.dll'` I guess this error will not pop up in Admin mode, or the dll just should not be deleted. – questionto42 Aug 15 '20 at 15:26
8

You can also use

conda remove torch torchvision

Please note that this will remove the specified packages (here: torch and torchvision) and any other package which depends on torch and torchvision, if there're any.

P.S. conda uninstall is an alias to conda remove.

kmario23
  • 57,311
  • 13
  • 161
  • 150
4

Perhaps @Schütze meant with "This does not remove all the files." that there are still files in the Anaconda\pkgs folder.

Mind that you can remove the tar.b2 and the folder of the now unused packages in Anaconda\pkgs. I uninstalled pytorch cuda version (because my display driver does not support cuda) and there were huge files there:

  • pytorch-1.5.0-py3.7_cuda102_cudnn7_0.tar.bz2
  • pytorch-1.5.0-py3.7_cuda102_cudnn7_0
  • cudatoolkit-10.2.89-h74a9793_1.conda
  • cudatoolkit-10.2.89-h74a9793_1

This makes 3 GB altogether! Either do this manually, or with a command:

to delete all unneeded packages:

    conda clean --yes --packages --dry-run

to delete all unneeded tar.bz2 / conda

    conda clean --yes --tarballs --dry-run

to delete all together

    conda clean --yes --all --dry-run

First use parameter --dry-run to see what will happen. Afterwards, run without --dry-run. This has cleaned about 3.5 GB of the used 7 GB disk space that was used by Anaconda\pkgs.

References: How to uninstall all unused packages in a conda virtual environment? and Anaconda Python: Delete .tar.gz in pkgs

user4157124
  • 2,809
  • 13
  • 27
  • 42
questionto42
  • 7,175
  • 4
  • 57
  • 90
0

You can safely delete the pytorch installation using the following conda command:

conda uninstall pytorch-cpu torchvision-cpu pytorch
-1

I recently found a good tool!

pip install pip-autoremove

This tool can delete all the tools you need to delete. For example, if you need to delete the torch, then it can delete torchvision as well!

Usage: pip-autoremove [OPTION]... [NAME]...

Options:
  --version     show program's version number and exit
  -h, --help    show this help message and exit
  -l, --list    list unused dependencies, but don't uninstall them.
  -L, --leaves  list leaves (packages which are not used by any others).
  -y, --yes     don't ask for confirmation of uninstall deletions.
Dany
  • 25
  • 1