How to Install and Import Keras in Anaconda/Jupyter Notebooks (2024)

How to Install and Import Keras in Anaconda/Jupyter Notebooks (1)

Do you work in Jupyter Notebooks and have an issue in installing and hence importing Keras? Well, you are at the right place.

I was in the same boat a few days back. I struggled for a few hours and could not get a breakthrough and gave up that day. The next day, I again started with a different approach and it clicked!

Just a disclaimer I work on Mac OSx Sierra(10.12.6) and this post is all about installing Keras and importing keras in Jupyter Notebook.

Installing Keras in Anaconda

So, first I did what I usually do to install any library.

pip install keras 

But, it did not actually work. When I tried to import keras in my Jupyter Notebook, I got the below error:

ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`

So, what I did next is to try installing tensorflow as per the error message. Guess what? I got another error:

ERROR: Cannot uninstall ‘wrapt’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

I tried uninstalling and then re-installing and keep on getting some error or another.

So, I did a couple of search in google and tried the below suggestions:

conda update wraptpip install tensorflowpip install tensorflow-gpu==1.14pip install tensorflow ==1.14

No! Nada! Nothing worked!

But finally, I got a solution which actually worked and it is simple! Stay tuned!

A Working Solution:

Step 1: Create a new environment

Open the terminaland create a new environment. I have named my environment “keras_env“.

condacreate--namekeras_env
Step 2: Activate the environment

Now, activate the environment created above.

conda activatekeras_env
Step 3: Install keras

To install keras, we need to type the below command:

conda install-canacondakeras

It will take some time to install.

How to Install and Import Keras in Anaconda/Jupyter Notebooks (2)

After analyzing, it will show a list of packages to be installed and will ask for a confirmation to proceed. Press Y to continue.

How to Install and Import Keras in Anaconda/Jupyter Notebooks (3)
Step 5: Import Keras in Jupyter Notebook

Once the installation is complete, open Anaconda Environments. The new environment created above should be there. For me, it is called “keras_env“. Now, search for the library Keras in the new environment. It should be right there if everything goes well.

How to Install and Import Keras in Anaconda/Jupyter Notebooks (4)

It should have also installed tensorflow.

How to Install and Import Keras in Anaconda/Jupyter Notebooks (5)

Now, go back home and check if the “Applications on” is set to the new environment. For me, it is keras_env.

How to Install and Import Keras in Anaconda/Jupyter Notebooks (6)

Finally, you are all set to open the Jupyter Notebook. So, when I clicked on Jupyter Notebook, it took some time to install first, and then it opened. You may get a message like below in Anaconda.

How to Install and Import Keras in Anaconda/Jupyter Notebooks (7)

Once the Jupyter Notebook is open, import keras and Voila!

How to Install and Import Keras in Anaconda/Jupyter Notebooks (8)

It took so much time to install and import keras that I totally forgot why I was even trying to import Keras!

Happy Learning and Happy Coding!

Please clap once if this post actually solve your problem.

Thank You!

359

How to Install and Import Keras in Anaconda/Jupyter Notebooks (2024)
Top Articles
Latest Posts
Article information

Author: Aron Pacocha

Last Updated:

Views: 6046

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Aron Pacocha

Birthday: 1999-08-12

Address: 3808 Moen Corner, Gorczanyport, FL 67364-2074

Phone: +393457723392

Job: Retail Consultant

Hobby: Jewelry making, Cooking, Gaming, Reading, Juggling, Cabaret, Origami

Introduction: My name is Aron Pacocha, I am a happy, tasty, innocent, proud, talented, courageous, magnificent person who loves writing and wants to share my knowledge and understanding with you.