Last modified: Jun 20, 2025 By Alexander Williams
How to Uninstall PyTorch in Python
PyTorch is a popular deep learning framework. Sometimes, you may need to uninstall it. This guide will show you how.
Why Uninstall PyTorch?
You might want to uninstall PyTorch for several reasons. Maybe you need a different version. Or you're troubleshooting issues.
Whatever the reason, proper uninstallation is important. It ensures no leftover files cause problems later.
Check Installed PyTorch Version
First, check if PyTorch is installed. Also note its version. This helps verify successful removal later.
import torch
print(torch.__version__) # Prints PyTorch version
1.12.1+cpu # Example output
Uninstall PyTorch Using pip
If you installed PyTorch with pip, use this method. Run the following command in your terminal.
pip uninstall torch torchvision torchaudio
The command removes PyTorch and its common extensions. Confirm the uninstallation when prompted.
Uninstall PyTorch Using conda
For conda installations, use this approach. Conda manages dependencies differently than pip.
conda uninstall pytorch torchvision torchaudio
This removes the PyTorch packages from your conda environment. Like pip, confirm the action when asked.
Verify PyTorch Uninstallation
After uninstalling, verify PyTorch is gone. Try importing it in Python.
import torch # Should raise ModuleNotFoundError if uninstalled
ModuleNotFoundError: No module named 'torch'
Clean Up Residual Files
Sometimes, files remain after uninstallation. These can cause issues. Here's how to find and remove them.
For pip installations, check your site-packages directory. Look for any torch-related folders.
For conda, check the environment's package directory. Remove any remaining PyTorch files manually.
Reinstall PyTorch (Optional)
If you uninstalled to fix issues, you may want to reinstall. Check the official PyTorch website for the correct install command.
This ensures you get a clean installation. It can resolve many common problems.
Troubleshooting Common Issues
Sometimes uninstallation fails. Here are solutions to common problems.
Permission errors: Try running the command with sudo (Linux/Mac) or as admin (Windows).
Partial uninstallation: Manually remove remaining files as described earlier.
Environment issues: Consider creating a new virtual environment. This gives you a clean slate.
Alternative Uninstall Methods
If standard methods fail, try these alternatives.
Use pip-autoremove
to remove PyTorch and its dependencies:
pip install pip-autoremove
pip-autoremove torch -y
This can be more thorough than regular pip uninstall.
Related Uninstall Guides
Need to uninstall other Python packages? Check these guides:
How to Uninstall TensorFlow in Python
How to Uninstall scikit-learn in Python
How to Uninstall Pandas in Python
Conclusion
Uninstalling PyTorch is straightforward. Use pip or conda depending on how you installed it.
Always verify the uninstallation was successful. Clean up any remaining files if needed.
For more complex setups, consider using virtual environments. They make package management easier.