How to Uninstall Keras in Python?

I was helping a data science team in San Francisco that faced version conflicts between TensorFlow and Keras. The issue was simple: multiple versions of Keras were installed across different Python environments, causing import errors.

I’ve personally encountered this problem many times while working with Python Keras for deep learning projects. The good news is that uninstalling Keras is simple, once you know the right commands for your platform.

In this tutorial, I’ll show you how to uninstall Keras completely from your system, whether you’re using Windows, macOS, Linux, Anaconda, or a virtual environment.

What is Keras in Python?

Before uninstalling, let’s quickly understand what Keras is.

Keras is a high-level deep learning API written in Python that runs on top of TensorFlow. It allows you to build and train neural networks easily.

However, sometimes you might need to uninstall Keras if:

  • You’re upgrading to a newer version of TensorFlow (which already includes Keras).
  • You’re facing version conflicts between TensorFlow and standalone Keras.
  • You want to clean up your Python environment.

Method 1 – Uninstall Keras Using pip (Recommended)

If you installed Keras using pip, you can uninstall it directly from the terminal or command prompt.

This is the most common and reliable way to remove Keras in Python.

Steps to uninstall Keras using pip:

  1. Open your Command Prompt (Windows) or Terminal (macOS/Linux).
  2. Type the following command and press Enter.
pip uninstall keras

You can see the output in the screenshot below.

Uninstall Keras in Python

After running this command, pip will ask for confirmation. Type y and press Enter to proceed.

If you also want to remove any dependencies related to Keras, you can use the following command:

pip uninstall keras tensorflow tensorflow-gpu

Tip:
Sometimes, multiple versions of Python are installed on your system. To make sure you’re uninstalling Keras from the correct version, use:

python -m pip uninstall keras

This ensures the uninstall command is executed for the specific Python version you’re using.

Method 2 – Uninstall Keras on Windows (Python Installed via pip)

When working on Windows systems, uninstalling Keras is straightforward using the Command Prompt.

Here’s how I usually do it when working on my Windows 11 machine.

Steps:

  1. Press Windows + R, type cmd, and hit Enter.
  2. Check if Keras is installed using:
pip show keras

If Keras is listed, proceed to uninstall it:

pip uninstall keras
  1. To verify the uninstallation, run:
pip list

If Keras no longer appears in the list, it’s successfully removed.

If you’re using Python 3, replace pip with pip3:

pip3 uninstall keras

Method 3 – Uninstall Keras on macOS

On macOS, you can use the Terminal to uninstall Keras.

I often use this method on my MacBook Pro when switching between TensorFlow and PyTorch environments.

Steps to uninstall Keras on macOS:

  1. Open the Terminal app.
  2. Type the following command:
pip3 uninstall keras
  1. Confirm the uninstallation when prompted.

To double-check that Keras is gone, run:

pip3 show keras

If no output appears, Keras has been successfully uninstalled.

Method 4 – Uninstall Keras on Linux

If you’re running Python on Ubuntu or any other Linux distribution, the process is similar. I often use this when managing cloud servers or Docker containers for deep learning experiments.

Steps to uninstall Keras on Linux:

  1. Open your terminal.
  2. Run the following command:
sudo pip3 uninstall keras
  1. Enter your system password when prompted.

To verify the uninstallation:

pip3 list | grep keras

If no output appears, Keras has been successfully removed.

Method 5 – Uninstall Keras in Anaconda (conda environment)

If you’re using Anaconda, Keras might have been installed using conda or pip inside a conda environment.

Here’s how to uninstall it properly.

Steps to uninstall Keras using conda:

  1. Open the Anaconda Prompt.
  2. Activate your environment (for example, tensorflow_env):
conda activate tensorflow_env
  1. Uninstall Keras:
conda remove keras
  1. Confirm by typing y when prompted.

If you installed Keras using pip inside the conda environment, use:

pip uninstall keras

To confirm, check the installed packages:

conda list | find "keras"

If no Keras package appears, it’s been successfully removed.

Method 6 – Uninstall Keras in a Virtual Environment

When working on Python projects, I always recommend using virtual environments. They isolate dependencies and prevent conflicts between packages like TensorFlow and Keras.

If you installed Keras inside a virtual environment, here’s how to remove it.

Steps:

  1. Activate your virtual environment:
# On Windows
venv\Scripts\activate

# On macOS/Linux
source venv/bin/activate
  1. Once activated, uninstall Keras:
pip uninstall keras
  1. To confirm removal:
pip list

If Keras no longer appears, it’s successfully uninstalled.

When you’re done, deactivate the virtual environment:

deactivate

Method 7 – Remove Keras Manually (if uninstall fails)

Sometimes, pip or conda might not remove all Keras files, especially if installations were done globally or manually.

In such cases, you can delete the Keras folder manually from your Python site-packages directory.

Steps to remove Keras manually:

  1. Locate your Python installation directory.
    For example:
  • Windows: C:\Users\<YourName>\AppData\Local\Programs\Python\Python310\Lib\site-packages\
  • macOS/Linux: /usr/local/lib/python3.10/site-packages/
  1. Find and delete the following folders (if they exist):
  • keras
  • keras_preprocessing
  • keras_applications
  1. Restart your terminal or IDE (like PyCharm, VS Code, or Jupyter Notebook).

Once deleted, Keras will be completely removed from your system.

Method 8 – Verify Keras Uninstallation in Python

After uninstalling, you can verify that Keras is no longer available in your Python environment.

Here’s a quick test you can run:

import keras

If Keras is successfully uninstalled, you’ll see an error like this:

ModuleNotFoundError: No module named 'keras'

This confirms that Keras has been completely removed.

Bonus Tip – Reinstall Keras (if needed)

If you ever want to reinstall Keras, you can do it easily using pip:

pip install keras

Or, if you’re using TensorFlow 2.x (which already includes Keras), you can directly import it like this:

from tensorflow import keras

This is the preferred modern way to use Keras in Python.

So that’s how you can uninstall Keras in Python, across Windows, macOS, Linux, Anaconda, and virtual environments.

While uninstalling Keras might seem like a small task, doing it properly ensures your Python environment stays clean and conflict-free. I always recommend using virtual environments or Anaconda for managing deep learning libraries, as it makes switching between frameworks like TensorFlow and PyTorch much smoother.

You may also read:

Leave a Comment

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.