卸载 PyTorchReferenceshttps://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.mdTo reinstall, first uninstall all existing PyTorch installs. You may need to runpip uninstall torchmultiple times. You’ll knowtorchis fully uninstalled when you seeWARNING: Skipping torch as it is not installed.重新安装 PyTorch 之前请先卸载所有已安装的 PyTorch。您可能需要多次运行pip uninstall torch。当您看到WARNING: Skipping torch as it is not installed时表示torch已完全卸载。You should only have topip uninstalla few times, but you can alwaysuninstallwithtimeoutor in a loop if you’re feeling lazy.你只需要运行几次pip uninstall torch即可但如果你懒得运行也可以使用timeout或循环运行uninstall。pip uninstall torchNext runpython setup.py clean. After that, you can install in editable mode again.接下来运行python setup.py clean。之后你就可以再次以可编辑模式安装。conda uninstall pytorch -y yes | pip uninstall torchUninstall all existing PyTorch installs:conda uninstall pytorch pip uninstall torch pip uninstall torch # run this command twiceyongqiangstrong-sys:~$ pip uninstall torch Uninstalling torch-1.0.0a046ef2b2: Would remove: /usr/local/lib/python2.7/dist-packages/caffe2 /usr/local/lib/python2.7/dist-packages/torch /usr/local/lib/python2.7/dist-packages/torch-1.0.0a046ef2b2.egg-info Proceed (y/n)? y Exception: Traceback (most recent call last): File /usr/local/lib/python2.7/dist-packages/pip/_internal/cli/base_command.py, line 143, in main status self.run(options, args) File /usr/local/lib/python2.7/dist-packages/pip/_internal/commands/uninstall.py, line 75, in run auto_confirmoptions.yes, verboseself.verbosity 0, File /usr/local/lib/python2.7/dist-packages/pip/_internal/req/req_install.py, line 683, in uninstall uninstalled_pathset.remove(auto_confirm, verbose) File /usr/local/lib/python2.7/dist-packages/pip/_internal/req/req_uninstall.py, line 224, in remove renames(path, new_path) File /usr/local/lib/python2.7/dist-packages/pip/_internal/utils/misc.py, line 280, in renames shutil.move(old, new) File /usr/lib/python2.7/shutil.py, line 300, in move rmtree(src) File /usr/lib/python2.7/shutil.py, line 247, in rmtree rmtree(fullname, ignore_errors, onerror) File /usr/lib/python2.7/shutil.py, line 252, in rmtree onerror(os.remove, fullname, sys.exc_info()) File /usr/lib/python2.7/shutil.py, line 250, in rmtree os.remove(fullname) OSError: [Errno 13] 权限不够: /usr/local/lib/python2.7/dist-packages/caffe2/proto/metanet_pb2.py yongqiangstrong-sys:~$ yongqiangstrong-sys:~$ sudo pip uninstall torch [sudo] yongqiang 的密码 The directory /home/yongqiang/.cache/pip/http or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudos -H flag. Uninstalling torch-1.0.0a046ef2b2: Would remove: /usr/local/lib/python2.7/dist-packages/caffe2 /usr/local/lib/python2.7/dist-packages/torch /usr/local/lib/python2.7/dist-packages/torch-1.0.0a046ef2b2.egg-info Proceed (y/n)? y Successfully uninstalled torch-1.0.0a046ef2b2 yongqiangstrong-sys:~$ yongqiangstrong-sys:~$ sudo pip uninstall torch The directory /home/yongqiang/.cache/pip/http or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudos -H flag. Skipping torch as it is not installed. yongqiangstrong-sys:~$ yongqiangstrong-sys:~$ python Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type help, copyright, credits or license for more information. import torchvision Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.7/dist-packages/torchvision/__init__.py, line 1, in module from torchvision import models File /usr/local/lib/python2.7/dist-packages/torchvision/models/__init__.py, line 1, in module from .alexnet import * File /usr/local/lib/python2.7/dist-packages/torchvision/models/alexnet.py, line 1, in module import torch.nn as nn ImportError: No module named torch.nn exit() yongqiangstrong-sys:~$yongqiangfamu-sys:~$ sudo pip uninstall torch yongqiangfamu-sys:~$ sudo pip3 uninstall torchyongqiangfamu-sys:~$ sudo pip uninstall torch DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 wont be maintained after that date. A future version of pip will drop support for Python 2.7. WARNING: The directory /home/yongqiang/.cache/pip/http or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudos -H flag. Uninstalling torch-1.0.1.post2: Would remove: /usr/local/bin/convert-caffe2-to-onnx /usr/local/bin/convert-onnx-to-caffe2 /usr/local/lib/python2.7/dist-packages/caffe2/* /usr/local/lib/python2.7/dist-packages/torch-1.0.1.post2.dist-info/* /usr/local/lib/python2.7/dist-packages/torch/* Proceed (y/n)? y Successfully uninstalled torch-1.0.1.post2 yongqiangfamu-sys:~$ yongqiangfamu-sys:~$ sudo pip3 uninstall torch WARNING: The directory /home/yongqiang/.cache/pip/http or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudos -H flag. Uninstalling torch-1.1.0: Would remove: /usr/local/lib/python3.5/dist-packages/caffe2/* /usr/local/lib/python3.5/dist-packages/torch-1.1.0.dist-info/* /usr/local/lib/python3.5/dist-packages/torch/* Proceed (y/n)? y Successfully uninstalled torch-1.1.0 yongqiangfamu-sys:~$References[1] Yongqiang Cheng (程永强), https://yongqiang.blog.csdn.net/[2] 卸载 PyTorch, https://mp.weixin.qq.com/s/CY6bQ17SXXiprF1Q7EhgYA