2

I tried to import the Keras library in Spyder but it throws an error:

Traceback (most recent call last):

  File "<ipython-input-8-c74e2bd4ca71>", line 1, in <module>
    import keras

ModuleNotFoundError: No module named 'keras'

Then I created a virtual environment and installed Keras in that:

cd virtualenv/
virtualenv -p python3.5 py-keras
source py-keras/bin/activate
pip install -q -U pip setuptools wheel
pip install keras

If I'm editing in that virtual env with the terminal I can import Keras successfully, whereas in Spyder it still throws the same error.

petezurich
  • 9,280
  • 9
  • 43
  • 57
popleye
  • 21
  • 1
  • 1
  • 2
  • I guess, you need to tell spyder to use the python from this venv. You can follow instructions from this post: https://stackoverflow.com/a/45219081/5538805 – Ahmed Dhanani Sep 26 '17 at 10:31
  • i've already tried that and it didnt worked ..btw thanks for reply :) – popleye Sep 26 '17 at 10:36

3 Answers3

1

If you have anaconda (as Sypder is a part of it) . Why don't you do

conda install keras

on terminal. It install and works without any problem on spyder.

vinay kusuma
  • 65
  • 1
  • 9
1

Did you try starting Spyder from the virtualenv as well? You can activate your virtualenv as you did:

source py-keras/bin/activate

Then start spyder with the appropriate command from the command line:

spyder
1

You will have the keras installed by using either ways. conda install keras from conda command prompt OR pip install keras from command prompt pointing to python36_64\Scripts. but, the only extra step you need to do to get that realized in Spyder console is close the Spyder console and launch it again through Anaconda Navigator. Use start > Anaconda Navigator -> Spyder. You should be able to import keras.

Deepak
  • 153
  • 1
  • 2