aerin
aerin

Reputation: 22634

How to check which version of Keras is installed?

Question is the same as the title says.

I prefer not to open Python and I use either MacOS or Ubuntu.

Upvotes: 105

Views: 279000

Answers (7)

MiniQuark
MiniQuark

Reputation: 48446

If you are using standalone Keras (pip install keras), then it's straightforward:

import keras
print(keras.__version__)

For Keras Core, the preview version of Keras 3 (pip install keras_core), it's simple as well:

import keras_core as keras
print(keras.__version__)

If you are using tf.keras—the Keras implementation bundled with TensorFlow (pip install tensorflow)—then the Keras API version depends on the TensorFlow version. You can try this:

import tensorflow as tf
print(tf.keras.__version__)  # works since TF version 1.9

Note that tf.keras.__version__ is unfortunately undefined in TensorFlow versions 2.13., 2.14., and 2.15.*.

Here's the mapping between TensorFlow version and Keras API version:

tf.__version__ tf.keras.__version__
≤1.8.* undefined
1.9.* 2.1.6-tf
1.10.* 2.1.6-tf
1.11.* 2.1.6-tf
1.12.* 2.1.6-tf
1.13.* 2.2.4-tf
1.14.* 2.3.0-tf (if tf2.enabled(), else 2.2.4-tf)
1.15.* 2.3.0-tf (if tf2.enabled(), else 2.2.4-tf)
2.0.* 2.3.0-tf (if tf2.enabled(), else 2.2.4-tf)
2.1.* 2.3.0-tf (if tf2.enabled(), else 2.2.4-tf)
2.2.* 2.3.0-tf (if tf2.enabled(), else 2.2.4-tf)
2.3.* 2.4.0
2.4.* 2.4.0
2.5.* 2.5.0
2.6.* 2.6.0
2.7.* 2.7.0
2.8.* 2.8.0
2.9.* 2.9.0
2.10.* 2.10.0
2.11.* 2.11.0
2.12.* 2.12.0
2.13.* undefined (but it's Keras 2.13.1)
2.14.* undefined (but it's Keras 2.14.0)
2.15.* undefined (but it's Keras 2.15.0)
2.16.* 3.6.0
2.17.* 3.6.0

Upvotes: 6

Joyanta J. Mondal
Joyanta J. Mondal

Reputation: 1047

For terminal, run: (Change with python3 for version of Python3)

python -c 'import keras; print(keras.__version__)'

Or if you want to check inside code, include:

import keras
print(keras.__version__)

Upvotes: 1

Ashish Tripathi
Ashish Tripathi

Reputation: 359

pip show tensorflow

C:\>pip show tensorflow
Name: tensorflow
Version: 2.4.1
Summary: TensorFlow is an open source machine learning framework for 
everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Requires: google-pasta, wheel, absl-py, flatbuffers, numpy, astunparse, opt- 
einsum, six, termcolor, typing-extensions, wrapt, grpcio, tensorboard, 
protobuf, tensorflow-estimator, gast, h5py, keras-preprocessing
Required-by:

Same way can try for

pip show keras

If it is installed then it will provide the details.

Upvotes: 6

rsnayak
rsnayak

Reputation: 350

Simple command to check keras version:

(py36) C:\WINDOWS\system32>python
Python 3.6.8 |Anaconda custom (64-bit) 

>>> import keras
Using TensorFlow backend.
>>> keras.__version__
'2.2.4'

Upvotes: 7

docjag
docjag

Reputation: 429

The simplest way is using pip command:

pip list | grep Keras

Upvotes: 18

aerin
aerin

Reputation: 22634

Python library authors put the version number in <module>.__version__. You can print it by running this on the command line:

python -c 'import keras; print(keras.__version__)'

If it's Windows terminal, enclose snippet with double-quotes like below

python -c "import keras; print(keras.__version__)"

Upvotes: 167

Noosh
Noosh

Reputation: 782

You can write:

python
import keras
keras.__version__

Upvotes: 43

Related Questions