How to Update Keras in Python

While working on a deep learning project in Python, I realized my Keras version was outdated. Some of the new features I wanted to use were missing, and my model wasn’t running as expected.

If you’ve ever faced this issue, you’re not alone. Updating Keras can sometimes feel confusing because there are multiple ways to install and manage it: pip, conda, or even directly in Jupyter Notebook.

In this article, I’ll walk you through all the possible methods to update Keras in Python, whether you’re using Windows, macOS, or Linux. I’ll also share some quick tips to verify your installation and troubleshoot common issues.

What Is Keras in Python?

Before we start updating, let’s quickly understand what Keras is.

Keras is a high-level deep learning framework written in Python. It allows you to build and train neural networks easily. It supports multiple backends like TensorFlow, JAX, and PyTorch, making it one of the most flexible frameworks available today.

If you want to use the latest features, bug fixes, and performance improvements, keeping Keras updated is essential.

Method 1 – Update Keras Using pip (Recommended for Most Users)

If you installed Keras using pip, the Python package manager, updating it is straightforward.

Before updating Keras, I always make sure my pip itself is up to date. This ensures compatibility and avoids installation errors.

Here’s the step-by-step process:

Step 1: Update pip

python -m pip install --upgrade pip

This command upgrades pip to the latest version. It’s a good habit to do this before updating any Python package.

Step 2: Update Keras

pip install --upgrade keras

That’s it! This command tells pip to fetch and install the latest version of Keras from PyPI. Once the installation completes, you can verify it by checking the version number.

Step 3: Verify Keras Version

import keras
print(keras.__version__)

I executed the above example code and added the screenshot below.

How to Update Python Keras

This will display the currently installed Keras version. If you see something like 3.x.x Congratulations, you’re now running the latest version of Keras!

Method 2 – Update Keras Using Conda (For Anaconda Users)

If you use Anaconda or Miniconda, you can update Keras through the conda command.

Sometimes, the Keras package in the default Anaconda channel is outdated. In that case, I recommend using the conda-forge channel, which usually has the latest version.

Here’s how you can do it.

Step 1: Open Anaconda Prompt (Windows) or Terminal (macOS/Linux)

Make sure you activate your desired environment first.

conda activate myenv

Step 2: Update Keras from conda-forge

conda install -c conda-forge keras --update-deps --force-reinstall

This command installs or updates Keras from the conda-forge channel and ensures that all dependencies are updated too.

Step 3: Verify Installation

import keras
print(keras.__version__)

You should now see the latest version number displayed.

Method 3 – Update Keras in Jupyter Notebook

If you primarily work in Jupyter Notebook, you can update Keras directly from within a notebook cell.

This method is convenient when you don’t want to switch to the terminal.

Step 1: Run the Upgrade Command

!pip install --upgrade keras

The exclamation mark allows you to run shell commands directly inside a notebook cell.

Step 2: Restart the Kernel

After the installation completes, restart your Jupyter Notebook kernel so that the new version of Keras is recognized.

Step 3: Verify the Update

import keras
print(keras.__version__)

You should now see the updated version printed in your notebook output.

Method 4 – Update Keras with TensorFlow

Since Keras is now integrated with TensorFlow (as tf.keras), updating TensorFlow automatically updates the bundled Keras version as well.

If you typically use tf.keras instead of standalone Keras, this method is perfect for you.

Step 1: Update TensorFlow

pip install --upgrade tensorflow

This command updates TensorFlow, which includes the latest compatible version of Keras.

Step 2: Verify the Version

import tensorflow as tf
print(tf.keras.__version__)

This will show you the Keras version that comes with your installed TensorFlow.

Method 5 – Update Keras Manually from Source (Advanced Users)

Sometimes, developers prefer to install Keras directly from its GitHub source to get the newest features before they’re officially released.

If you’re comfortable with Python development and want the cutting-edge version, this method is for you.

Step 1: Uninstall Existing Keras

pip uninstall keras -y

Step 2: Clone the Official Repository

git clone https://github.com/keras-team/keras.git

Step 3: Install from Source

cd keras
pip install .

This installs Keras directly from the source code. You can now use the latest development version.

Troubleshoot Common Issues

Even though updating Keras is usually smooth, sometimes you might run into issues. Here are a few quick fixes I’ve learned over the years:

  • Problem: “Keras not found” after update
    Solution: Restart your IDE or Jupyter Notebook kernel.
  • Problem: Version mismatch between TensorFlow and Keras
    Solution: Update both TensorFlow and Keras together using pip install –upgrade tensorflow keras.
  • Problem: Permission denied error
    Solution: Run the command with admin rights or use –user flag, like this:
  pip install --user --upgrade keras

How to Check Your Python and Keras Environment

Sometimes, version conflicts occur because of multiple Python environments. You can check your Python version and environment path using the following commands:

python --version
where python  # On Windows
which python  # On macOS/Linux

And to confirm your Keras installation path:

import keras
print(keras.__file__)

This helps you verify that you’re updating the correct environment.

Best Practices for Managing Keras Updates

After working with Python and Keras for over three years, here are some personal tips I always follow:

  • Always create a virtual environment before updating major libraries.
  • Keep TensorFlow and Keras versions compatible.
  • Regularly check release notes for breaking changes.
  • Use requirements.txt to track your project dependencies.

Here’s a quick command to export your dependencies:

pip freeze > requirements.txt

And to reinstall them later:

pip install -r requirements.txt

This ensures your environment remains consistent across updates.

Updating Keras in Python is not as complicated as it seems once you understand the different methods.

Whether you use pip, conda, or Jupyter Notebook, the key is to keep your environment clean and consistent. Personally, I prefer using pip because it’s fast, reliable, and works across all platforms.

By keeping your Keras version up to date, you’ll have access to the latest deep learning tools, improved performance, and better compatibility with TensorFlow and other frameworks.

You may 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.