ImportError: No module named keras.optimizers

7,234 views
Skip to first unread message

Abder-Rahman Ali

unread,
Aug 22, 2016, 10:18:20 AM8/22/16
to Keras-users
Hello,

I have this import statement in Keras:

    from keras.optimizers import SGD, RMSprop

But getting this error on this error:

    ImportError: No module named keras.optimizers

Why is that? And, how can I solve this issue?

Thanks.

Daπid

unread,
Aug 22, 2016, 10:27:45 AM8/22/16
to Abder-Rahman Ali, Keras-users
You most likely have an old version of keras. Update it with pip
install -U keras
> --
> 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/9b2a26ef-82f7-4e25-85cf-7d16116cd3f1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Abder-Rahman Ali

unread,
Aug 22, 2016, 10:32:43 AM8/22/16
to Keras-users
I realized this is due to the fact that in a previous installation Keras wasn't actually installed, as I got "could not create '/usr/local/lib/python2.7/dist-packages/keras': Permission denied". I then used "sudo pip install keras" to install Keras properly.

Imran Khan

unread,
May 31, 2021, 1:40:10 PM5/31/21
to Keras-users
Hey bro, I'm getting this error even though I'm using both latest versions of tensorflow and keras

Lance Norskog

unread,
May 31, 2021, 6:28:37 PM5/31/21
to Imran Khan, Keras-users
Try:

from tensorflow.keras.optimizers import SGD, RMSprop

The latest 'keras' package is, in general, a wrapper for 'tensorflow.keras'.

--
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.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA

Imran khan

unread,
May 31, 2021, 6:35:33 PM5/31/21
to Lance Norskog, Keras-users
Thanks for the reply, I already did that and it worked fine. Thank you anyway appreciate that :))

roxanne weeks

unread,
Aug 26, 2021, 5:57:58 PM8/26/21
to Keras-users
Use tensorflow.keras.optimizers

Naga Satya

unread,
Oct 1, 2021, 12:26:55 AM10/1/21
to Keras-users
Try using from keras.optimizer_v1 import Adam.
There are some updates and optimisers are present in this optimiser_v1 subclass

lance....@gmail.com

unread,
Oct 4, 2021, 1:06:13 AM10/4/21
to Keras-users
Also, if you are still using Python 2.x, installing packages is going to get more and more difficult.

Cheers,

Lance Norskog

Shahzad Ahmad Khan

unread,
Oct 25, 2021, 5:23:55 AM10/25/21
to Keras-users
use this 
from keras.optimizers import gradient_descent_v2

instead of :

from keras.optimizers import SGD

Reply all
Reply to author
Forward
0 new messages