Python Forum
Installing keras in Python 2.7 environment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Installing keras in Python 2.7 environment
#1
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
Reply
#2
Looking around for keras for 2.7, I think this will work

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

Thanks for your help!

Respectfully,

ErnestTBass
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Installing python packages in a virtual environment Led_Zeppelin 1 764 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,267 May-10-2023, 02:13 PM
Last Post: Calab
  Python development environment standenman 3 1,624 May-04-2023, 07:24 PM
Last Post: snippsat
  Python Scripting Environment jpotter0 1 1,713 Nov-19-2022, 03:07 PM
Last Post: snippsat
  How do I link the virtual environment of that project to the 3.9.2 version of python? Bryant11 1 1,374 Feb-26-2022, 11:15 AM
Last Post: Larz60+
  VS Code debugger using wrong Python environment topfox 0 2,510 Jun-09-2021, 10:01 AM
Last Post: topfox
  It says there is no keras in jupyter notebook. it is wrong there is a keras install Led_Zeppelin 0 1,885 Apr-27-2021, 08:29 PM
Last Post: Led_Zeppelin
  Virtual environment and upgrading python 3.5 to 3.9 NeilUK 4 12,141 Jan-24-2021, 01:02 PM
Last Post: snippsat
  Python in Linux environment on RPI kendias 22 11,092 Sep-05-2020, 03:04 AM
Last Post: K_Research
  Unable to install virtual environment on python 3.8.3 Allen10 4 3,136 Jun-04-2020, 04:22 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020