2
votes

I am using anaconda 4.4.0 with Python 3.6.2. First, I pip installed Keras, it shows on pip list and conda list and also in environment>root>packages in Anaconda. But when I use import keras ,in Anaconda or in Terminal, I get

Traceback (most recent call last): ... ModuleNotFoundError: No module named 'keras'

I tried installing Keras with anaconda also, and I get the same ModuleNotFoundError.

I have also tried uninstalling it, then download the master branch from github and install using python setup.py install. Again the package is in the lists but I cannot import it.

UPDATE:

I have uninstalled packages several times and installed using Keras package in pypi, Now I am able to import the packages in the python in terminal. But still I cannot import in jupyter notebook.

It may worth mentioning that I am working with MacOS Sierra 10.

4
what 'which python' says? - Vadim
~/anaconda3/bin/python @Paddy - Sha2b
I have the same issue - user1761806

4 Answers

1
votes

If you are able to import in shell but not in the notebook, according to gnestor's answer to this question, your python may use different executables. Run:

import sys
sys.executable

in shell and in notebook. If the directories are different then you must change the kernelspec of the notebook. This might have happened by installing Tensorflow or other packages that change the environment and kernelspec. You can find the kernelspec directory with this command:

from jupyter_core.paths import jupyter_data_dir
print(jupyter_data_dir())

In that directory you will find a JSON file. Open it and change the path to your working python directory. (working python directory in which python)

0
votes

use python -m pip install keras

Then, use python shell to check for installation.

0
votes

try this code:

conda install -c deeplearn keras

Basically, the full answer you can find here: Install Python package: "Package missing in current win-64 channels"

However, it seems to me you are using different python in your terminal. Check this command in the terminal:

which python 

It should return something like this:

/Users/***/anaconda3/bin/python
0
votes

Try running:

conda install jupyter
conda install tensorflow
pip install Keras

with your conda environment activated. Don't ask me why - Anaconda's behavior baffles me. (I've created a .yml script with these yet I still seem to need to do this step)