![How to Install and Import Keras in Anaconda/Jupyter Notebooks (1) How to Install and Import Keras in Anaconda/Jupyter Notebooks (1)](https://i0.wp.com/oindrilasen.com/wp-content/uploads/2021/02/keras.png)
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) How to Install and Import Keras in Anaconda/Jupyter Notebooks (2)](https://i0.wp.com/oindrilasen.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-19-at-11.01.17-AM.png)
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) How to Install and Import Keras in Anaconda/Jupyter Notebooks (3)](https://i0.wp.com/oindrilasen.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-19-at-11.02.49-AM.png)
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) How to Install and Import Keras in Anaconda/Jupyter Notebooks (4)](https://i0.wp.com/oindrilasen.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-19-at-2.58.43-PM-1024x264.png)
It should have also installed tensorflow.
![How to Install and Import Keras in Anaconda/Jupyter Notebooks (5) How to Install and Import Keras in Anaconda/Jupyter Notebooks (5)](https://i0.wp.com/oindrilasen.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-19-at-3.00.45-PM-1024x279.png)
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) How to Install and Import Keras in Anaconda/Jupyter Notebooks (6)](https://i0.wp.com/oindrilasen.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-19-at-2.50.13-PM.png)
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) How to Install and Import Keras in Anaconda/Jupyter Notebooks (7)](https://i0.wp.com/oindrilasen.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-19-at-2.50.02-PM.png)
Once the Jupyter Notebook is open, import keras and Voila!
![How to Install and Import Keras in Anaconda/Jupyter Notebooks (8) How to Install and Import Keras in Anaconda/Jupyter Notebooks (8)](https://i0.wp.com/oindrilasen.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-19-at-3.19.16-PM.png)
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