How to uninstall TensorFlow from your computer

The Python tensorflow package is known to be difficult to uninstall because there are many ways to install it on your machine.

The first command you should try is to use pip to uninstall the package:

sudo pip uninstall tensorflow
# If you have tensorflow-gpu
sudo pip uninstall tensorflow-gpu

# Or pip3:
sudo pip3 uninstall tensorflow
sudo pip3 uninstall tensorflow-gpu

If you didn’t use sudo to install the package, then you don’t need it to uninstall:

pip uninstall tensorflow

# Or pip3:
pip3 uninstall tensorflow

If that doesn’t work, then try to use the python -m command to run library module as a script:

python -m pip uninstall tensorflow

# For python3:    
python3 -m pip uninstall tensorflow

If you have the older tensorflow-gpu package, uninstall it using one of the commands below:

pip uninstall tensorflow-gpu

# Or pip3:
pip3 uninstall tensorflow-gpu

If you installed TensorFlow using conda, then you can use the conda remove command as follows:

conda remove tensorflow
# or:
conda uninstall tensorflow

If you installed TensorFlow on Apple Silicon Macs, then use this command to uninstall it:

pip3 uninstall tensorflow-macos
pip3 uninstall tensorflow-metal

Apple Silicon Macs have a special TensorFlow version that uses the Metal API to gain access to the GPU.

If you’re using a Windows computer, then you might get a FileNotFoundError when running the pip uninstall tensorflow command.

This error happens because Windows can’t delete a file that has a path longer than 260 characters. Follow this guide to remove that limit.

If you still see the error, then you can try to delete the package manually from the site-packages folder.

To get the location of your package, run the pip show command as follows:

$ pip3 show tensorflow-metal
Name: tensorflow-metal
Version: 0.7.1
Summary: TensorFlow acceleration for Mac GPUs.
Home-page: https://developer.apple.com/metal/tensorflow-plugin/
Author: 
Author-email: 
License: MIT License. Copyright © 2020-2021 Apple Inc. All rights reserved.
Location: /opt/homebrew/lib/python3.10/site-packages
Requires: six, wheel
Required-by: 

As you can see, pip shows the location where the package is installed. Go into the folder and delete the tensorflow folder. You might need to add the sudo privilege on Linux and Mac.

Finally, if you use a virtual environment to install the tensorflow package, make sure that the environment is activated before you uninstall it.

You can see if a virtual environment is activated or not by looking at your command prompt.

When a virtual environment is activated, the name of that environment will be shown inside parentheses as shown below:

In the picture above, the name of the virtual environment (base) appears when the Conda virtual environment is activated.

Once activated, you can uninstall the package using either pip or conda commands.

I hope this tutorial helps you to remove TensorFlow from your computer. See you in other tutorials! 👋

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.