0

I want to use keras with the code shown below:

from sklearn.model_selection import train_test_split
from keras.models import Sequential
df = DataReader('AAPL', data_source='yahoo', start='2012-01-01', end=datetime.now())

but I keep getting the error:

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

I have both keras 2.4.3 and tensorflow 2.2.0 installed in anaconda environment. I uninstalled and installed jupiter notebook but it didn't help.

Hagbard
  • 3,430
  • 5
  • 28
  • 64
Vivi
  • 21
  • 1
  • 4
  • When you're using keras with tensorflow, you shoudl use the tensorflow.keras package instead – Benjamin Jul 14 '20 at 10:25
  • Update the question with the code that is causing the error. – Imanpal Singh Jul 14 '20 at 10:58
  • @Benjamin, thanks for writing. There is no package tensorflow.keras in Anaconda environment. I tried installing keras-gpu, but I got the following message UnsatisfiableError: The following specifications were found to be incompatible with each other: Output in format: Requested package -> Available versions – Vivi Jul 15 '20 at 12:53
  • anaconda's tensorflow project has already this package – Benjamin Jul 15 '20 at 13:09
  • I solved the problem by simply installing different versions of keras (2.3.1 instead of 2.4.3) and tensorflow (2.0.0 instead of 2.2.0). – Vivi Jul 16 '20 at 14:27
  • 1
    @Vivi - use `import tensorflow as tf; tf.keras` instead of `import keras`. – jkr Jul 28 '20 at 12:40
  • Does this answer your question? [Error "Keras requires TensorFlow 2.2 or higher"](https://stackoverflow.com/questions/62465620/error-keras-requires-tensorflow-2-2-or-higher) – Channa Jan 11 '21 at 04:23

1 Answers1

0

From comments

Solved the problem by simply installing different versions of keras (2.3.1 instead of 2.4.3) and tensorflow (2.0.0 instead of 2.2.0). Keras are integrated with Tensorflow from 2.3 onwards, you can upgrade tensorflow to latest version and use module tf.keras (paraphrased from Vivi and jakub)

To run code in TF 2.4 is as shown below

from sklearn.model_selection import train_test_split
from tensorflow.keras import Sequential
df = DataReader('AAPL', data_source='yahoo', start='2012-01-01', end=datetime.now())