在 Ubuntu 上把 PyTorch 卸载干净,取决于你是用什么方式安装的(pip / conda / apt)。下面分情况说明,按你实际用的来。
pip list | grep torch
常见包有:
pip uninstall torch torchvision torchaudio torchtext -y
如果是用户级安装(–user):
pip uninstall torch torchvision torchaudio -y --user
python -c "import torch"
如果还报错说明已卸载;如果还能 import,看下一步。
rm -rf ~/.cache/torch
rm -rf ~/.cache/pip
conda activate your_env_name
conda remove torch torchvision torchaudio -y
conda remove -n your_env_name --all
dpkg -l | grep torch
sudo apt remove --purge libtorch* -y
sudo apt autoremove -y
which python
python -c "import torch"
应该出现:
ModuleNotFoundError: No module named 'torch'
which python
which python3
pip --version
确保你卸载的是 正在用的那个 Python。
pip3 uninstall torch -y
conda / venv 没激活就卸载,等于没删。
如果你愿意,可以告诉我:
pip list | grep torch 的输出我可以帮你一步步清到“一根毛都不剩”。