Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras No module named models

Tags:

python

keras

Try to run Keras in MacOSX, using a virtual environment

Versions

  • MacOSX: 10.12.4 (16E195)
  • Python 2.7

Troubleshooting

  • Recreate Virtualenv
  • Reinstall keras

Logs

(venv) me$sudo pip install --upgrade keras

Collecting keras
Requirement already up-to-date: six in /Library/Python/2.7/site-packages/six-1.10.0-py2.7.egg (from keras)
Requirement already up-to-date: pyyaml in /Library/Python/2.7/site-packages (from keras)
Requirement already up-to-date: theano in /Library/Python/2.7/site-packages (from keras)
Requirement already up-to-date: numpy>=1.9.1 in /Library/Python/2.7/site-packages (from theano->keras)
Requirement already up-to-date: scipy>=0.14 in /Library/Python/2.7/site-packages (from theano->keras)
Installing collected packages: keras
Successfully installed keras-2.0.5

(venv) me$ python -c "import keras; print(keras.__version__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named keras
like image 563
gogasca Avatar asked Jun 18 '17 07:06

gogasca


1 Answers

The underlying problem here is what when you use sudo, pip points to the global, system-level python and not the virtual-env python. That is why, when you install without sudo, it works seamlessly for you. You can check this by running sudo pip install --upgrade keras from within the virtualenv and then running python -c "import keras; print(keras.__version__)" outside the virtualenv.

like image 136
Shagun Sodhani Avatar answered Oct 20 '22 11:10

Shagun Sodhani