Search code examples
pythontensorflowkerasjupyter-notebookanaconda

jupyter notebook can not import keras


I have installed Keras and TensorFlow-GPU but when I try to import these libraries into Jupiter notebook there is an error

Keras-applications        1.0.8                    pypi_0    pypi
keras-preprocessing       1.1.2                    pypi_0    pypi
tensorboard               2.1.1                    pypi_0    pypi
tensorflow-gpu            2.1.0                    pypi_0    pypi
tensorflow-gpu-estimator  2.1.0                    pypi_0    pypi
numpy                     1.19.2                   pypi_0    pypi
opencv-python             4.4.0.44                 pypi_0    pypi
pip                       19.2.3                   py37_0

here are the libraries using conda list . and here is the error that jupyter displays to me :

ModuleNotFoundError Traceback (most recent call last) in ----> 1 import keras 2 from keras.models import Sequential 3 from keras.layers import Dense, Activation 4 import numpy as np 5

ModuleNotFoundError: No module named 'keras'

I try this one in anaconda environment:

pip3 install keras

Requirement already satisfied: keras in c:\users\msi-pc\appdata\local\programs\python\python39\lib\site-packages (2.4.3) Requirement already satisfied: numpy>=1.9.1 in c:\users\msi-pc\appdata\local\programs\python\python39\lib\site-packages (from keras) (1.19.4) Requirement already satisfied: scipy>=0.14 in c:\users\msi-pc\appdata\local\programs\python\python39\lib\site-packages (from keras) (1.5.4) Requirement already satisfied: h5py in c:\users\msi-pc\appdata\local\programs\python\python39\lib\site-packages (from keras) (3.1.0) Requirement already satisfied: pyyaml in c:\users\msi-pc\appdata\local\programs\python\python39\lib\site-packages (from keras) (5.3.1)

I'm grateful if you help me.

P. S : I realized that in order to import keras /tensorflow from the second version on (tensorflow>=2.0.0 ) i have to use import tensorflow.keras And everything will be good.


Solution

  • If you're using tensorflow >= 2.0, then import keras using

    from tensorflow import keras
    

    Common convention is to import it as kr