ImportError: No module named 'keras'

2019-06-28 05:54发布

So basically, I am fairly new to programming and using python. I am trying to build an ANN model for which I have to use Tensor flow, Theano and Keras library. I have Anaconda 4.4.1 with Python 3.5.2 on Windows 10 x64 and I have installed these libraries by following method.

  1. Create a new environment with Anaconda and Python 3.5: conda create -n tensorflow python=3.5 anaconda
  2. Activate the environment: activate tensorflow
  3. After this you can install Theano, TensorFlow and Keras: conda install theano, conda install mingw libpython, pip install tensorflow, pip install keras,
  4. Update the packages: conda update --all

All these packages are installed correctly and I have check them with conda list. However, when I am trying to import any of these 3 libraries (i.e. Tensor flow, Theano and Keras), it is giving me the following error:

Traceback (most recent call last):
File "<ipython-input-3-c74e2bd4ca71>", line 1, in <module>
import keras
ImportError: No module named 'keras'

5条回答
Viruses.
2楼-- · 2019-06-28 06:32

Try

import sys
print(sys.path)

and see if your anaconda site-packages folder is in the list.

It should be something like WHERE_YOU_INSTALLED_ANACONDA\anaconda3\envs\ENVIRONMENT_NAME\lib\python3.5\site-packages

If the path setting is correct, then try listing the folder content, and see if Keras, TensorFlow and Theano are in this folder.

查看更多
叛逆
3楼-- · 2019-06-28 06:32

Click Update Index and then try searching for Keras again.

查看更多
成全新的幸福
4楼-- · 2019-06-28 06:45

Hi I have an solution try this if you are using Anaconda-Navigator

go to Anaconda Environment and search keras package and then install.

install keras

enter image description here

after install just type import keras in shell its working.

enter image description here

查看更多
霸刀☆藐视天下
5楼-- · 2019-06-28 06:52

I spent the whole day to install Keras, tried all the available methods online, almost dying. But I still cannot import keras.

(1). After using conda install or pip install, and delete the "1 > null > 2&1" ... I activated in conda prompt by activating tensorflow_cpu, it doesn't work anyway.

(2). Then checked the keras, and print os.path(), no virtual environment inside. I got so braindead, just copied all the keras data file from virtual environment env, and put into the "C:\Users\Administrator\Anaconda3\Lib\site-packages".

(3). Now, tensorflow and keras work well.

查看更多
SAY GOODBYE
6楼-- · 2019-06-28 06:55

I ran into a very similar issue after switching computers and downloading the latest Anaconda, which comes with python 3.6. It was no problem to install python 3.5 in its own environment, and install keras to this environment, but import keraskept failing.

My inelegant solution (assuming you've already got tensorflow/theano/cntk working fine in your global environment)?

Move the keras folder installed to Anaconda3/envs//Lib/site-packages/keras to Anaconda3/Lib/site-packages/keras. Now import keras gives a depreciation warning when run from a jupyter notebook launched via start menu, but it does work, and correctly returns the backend keras is running on.

查看更多
登录 后发表回答