Sha2b Sha2b - 25 days ago 14
Python Question

Keras in `pip list` and anaconda package list but cannot import

I am using anaconda 4.4.0 with Python 3.6.2. First, I pip installed Keras, it shows on

pip list
conda list
and also in
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

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


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.

Answer Source

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

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

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)