Multiple keras versions in python 2.7

803 views
Skip to first unread message

BorjaH_85

unread,
Feb 14, 2017, 11:30:26 AM2/14/17
to Keras-users
Hello all,

Nowadays I'm working with keras 1.0.5, but I would like to install 1.2.2 to test new functionalities. I have installed the newest library via setup.py install. When I execute sys.path command I can see that both packages are defined in the PYTHONPATH.

['C:\\eclipse\\plugins\\org.python.pydev_5.1.2.201606231256\\pysrc',
 'C:\\Anaconda2\\lib\\site-packages\\keras-1.2.2-py2.7.egg',
 'C:\\Anaconda2\\DLLs',
 'C:\\Anaconda2\\lib',
 'C:\\Anaconda2\\lib\\lib-tk',
 'C:\\Anaconda2',
 'C:\\Anaconda2\\lib\\site-packages',
 'C:\\Anaconda2\\lib\\site-packages\\Sphinx-1.4.1-py2.7.egg',
 'C:\\Anaconda2\\lib\\site-packages\\win32',
 'C:\\Anaconda2\\lib\\site-packages\\win32\\lib',
 'C:\\Anaconda2\\lib\\site-packages\\Pythonwin',
 'C:\\Anaconda2\\lib\\site-packages\\setuptools-23.0.0-py2.7.egg',
 'C:\\Anaconda2\\lib\\site-packages\\theano-0.8.2-py2.7.egg',
 'C:\\Anaconda2\\lib\\site-packages\\python_docx-0.8.6-py2.7.egg',
 'C:\\Anaconda2\\lib\\site-packages\\xgboost-0.6-py2.7.egg',
 'C:\\Anaconda2\\lib\\site-packages\\keras-1.0.5-py2.7.egg',
 'C:\\Anaconda2\\python27.zip',
 'C:\\Anaconda2\\lib\\plat-win',
 'C:\\Anaconda2\\lib\\site-packages\\IPython\\extensions']

When I import keras, the newest version (1.2.2) is imported. But, when I try to fix the oldest version (1.0.5):

import pkg_resources
pkg_resources.require("keras==1.0.5")
import keras

I receive the next version conflict message:

VersionConflict: (keras 1.2.2 (c:\anaconda2\lib\site-packages\keras-1.2.2-py2.7.egg), Requirement.parse('keras==1.0.5'))

Could someone help me in this?

Best,

Tomasz Melcer

unread,
Feb 14, 2017, 1:36:54 PM2/14/17
to Keras-users
On 02/14/2017 05:30 PM, BorjaH_85 wrote:
> Nowadays I'm working with keras 1.0.5, but I would like to install 1.2.2
> to test new functionalities. I have installed the newest library via
> setup.py install. When I execute sys.path command I can see that both
> packages are defined in the PYTHONPATH.
>
> […]
>
> I receive the next version conflict message:
>
> VersionConflict: (keras 1.2.2
> (c:\anaconda2\lib\site-packages\keras-1.2.2-py2.7.egg),
> Requirement.parse('keras==1.0.5'))
>
> Could someone help me in this?

Instead of trying to make this work manually, the usually suggested way
is to make use of virtual environments. Here is a nice tutorial on how
to make use of them in Anaconda [1].

[1]
https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/

IIRC there's no dedicated conda package for keras, but you can get one
from PyPI (instead of building it manually!). Therefore, the following
steps should work (from memory):

1. Create a virtual environment, name it, let say, "newkeras"

2. `activate newkeras`

3. `conda install theano` (take theano from Anaconda, because it drags
all the compiler stuff with dependencies then)

4. `pip install keras==1.2.2`

5. Run your code in the same terminal window.

Similarly, you can create a separate virtual environment with old keras
and switch between the two when necessary with `activate`.


--
Tomasz Melcer

BorjaH_85

unread,
Feb 23, 2017, 11:43:26 AM2/23/17
to Keras-users
Dear Tomasz,

Thanks a lot for your feedback. Really appreciated.

Actually I was aware that the best option was an environemtn variable, but I was just exploring if there are other alternatives considering that in this case just one library (Keras) were necessary to duplicate. 

Nevertheless, thanks a lot for your feedback.

Daπid

unread,
Feb 23, 2017, 1:53:52 PM2/23/17
to BorjaH_85, Keras-users
This is just the way Python is set up, there is only one version of
each library at any given point.

I actually think that clonating a virtual environment and then
changing the specific version you want is an elegant solution.
> --
> You received this message because you are subscribed to the Google Groups
> "Keras-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to keras-users...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/keras-users/a142528a-c8af-49e8-a981-80313c16c848%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

BorjaH_85

unread,
Feb 27, 2017, 4:02:06 AM2/27/17
to Keras-users
Yes you are right. Clonating a virtual environmetn is a great solution. But I was just wondering if other alternatives exist

Best
Reply all
Reply to author
Forward
0 new messages