Uninstall TensorFlow: The Unofficial Troubleshooting Guide

Ben Cook • Posted 2020-12-23 • Last updated 2022-11-16

There are lots of ways to install TensorFlow, which means (unfortunately) there is no one-size-fits-all solution for uninstalling it. The internet is littered with questions from frustrated developers and data scientists trying to remove this behemoth from their machines.

This post enumerates the solutions I’ve seen.

Uninstall TensorFlow

If you installed TensorFlow with pip

  • In most cases, you should be able to run: pip uninstall tensorflow
  • Or, if you installed tensorflow-gpu: pip uninstall tensorflow-gpu
  • Once in a while, the pip in your current path is not the same pip you used to install it. In this case, find the Python environment where the TensorFlow install lives and run: /path/to/python -m pip uninstall tensorflow

If you installed TensorFlow with conda

  • If you want to reuse your conda environment, you can run: conda remove tensorflow
  • If you’re willing to start a new conda environment, just remove the current one: conda remove --name <your environment> --all

If you built TensorFlow from source

  • Go to the source directory and run: python setup.py develop --uninstall

If you’re on Windows and you’re still having trouble

Finally, if one of the solutions above worked, you may also want to remove the packages TensorFlow installs automatically.

Alternatives

On the other hand, you may not actually need to uninstall TensorFlow. Here are a few alternatives to consider.

If you want to use TensorFlow in your current environment

  • You can upgrade the package: pip install tensorflow --upgrade

You can setup a virtual environment

  • You probably want to use Anaconda: conda create --name tensorflow-env python=3.8 pip tensorflow
  • But you can also use virtualenv. This requires a few commands:
    1. python -m venv tensorflow-venv
    2. source tensorflow-env/bin/activate
    3. pip install tensorflow

You can use Docker

The TensorFlow docs have a good page on using Docker for TensorFlow. Ultimately, this is what I would recommend if you can make it work. Getting TensorFlow off your actual machine and into Docker will save you headaches down the road.

What am I missing?

I hope this helps. Did I miss something obvious? Let me know in the comments section.