Python Forum

Full Version: Installing keras in Python 2.7 environment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have an virtual environment with python 2.7 installed. I know that I should not be using
Python 2.7, but the source code that I found (I did not write it) is in python 2.7. I would like to install keras, specifically for python 2.7. I believe hat this can be done. I just do not know how.

I can not just activate the environment with python 2.7, and then type

conda install keras

That will not work. Since the code that I have is using this version of python with keras there must be these modules available somewhere. The question is where and how to install them.

So how do I install keras in a python 2.7 environment?

Any help appreciated. Thanks in advance.

Respectfully,

ErnestTBass
Looking around for keras for 2.7, I think this will work

pip install Keras==2.2.4
See This PyPi page
Now will this also install tensorflow. I know that tensorflow and keras travel together.

Thanks for your help!

Respectfully,

ErnestTBass
Probably not. It's an older Keras which was not as tightly bound to Tensorflow, in fact would support a couple of other back end engines.

Looking around, I saw this on Stack Overflow:
Quote:13

If you only need TensorFlow because of Keras and your are on Python 2.7.x, you can avoid installing Tensorflow(Google) and replace it by CNTK(Microsoft). According to Jeong-Yoon Lee CNTK is a lot (about 2 to 4 times) faster than TensorFlow for LSTM (Bidirectional LSTM on IMDb Data and Text Generation via LSTM), while speeds for other type of neural networks are close to each other. Your Keras code does not need to be modified (I checked it with 2 examples of Keras using TensorFlow and succesfully replaced TensorFlow with CNTK, without changing anything the Keras code.

So how do you install it?

-CPU-only version of CNTK:

pip install https://cntk.ai/PythonWheel/CPU-Only/cnt..._amd64.whl

-GPU version of CNTK:

pip install https://cntk.ai/PythonWheel/GPU/cntk-2.4..._amd64.whl

-Test CNTK install:

python -c "import cntk; print(cntk.version)"

-Install Keras: The Python Deep Learning library

pip install keras

-Enable CNTK as Keras back end iso TensorFlow

modify the "keras.json" file under %USERPROFILE%/.keras

{
"epsilon": 1e-07,
"image_data_format": "channels_last",
"backend": "cntk",
"floatx": "float32"
}

You are unlikely to be able to install Tensorflow v2. You might see if THIS version will install