2

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.

Sha2b
  • 447
  • 1
  • 5
  • 12

4 Answers4

1

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)

Sha2b
  • 447
  • 1
  • 5
  • 12
0

use python -m pip install keras

Then, use python shell to check for installation.

Vasif
  • 1,393
  • 10
  • 26
  • I get the _requirements already satisfied_ and after installing it I still cannot import it in Anaconda. – Sha2b Aug 24 '17 at 19:16
0

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
Vadim
  • 4,219
  • 1
  • 29
  • 44
  • For conda install I get `PackageNotFoundError: Packages missing in current channels` – Sha2b Aug 24 '17 at 19:04
  • $ conda install -c deeplearn keras PackageNotFoundError: Packages missing in current channels: - keras We have searched for the packages in the following channels: - https://conda.anaconda.org/deeplearn/osx-64 - https://conda.anaconda.org/deeplearn/noarch - https://repo.continuum.io/pkgs/free/osx-64 - https://repo.continuum.io/pkgs/free/noarch - https://repo.continuum.io/pkgs/r/osx-64 - https://repo.continuum.io/pkgs/r/noarch - https://repo.continuum.io/pkgs/pro/osx-64 - https://repo.continuum.io/pkgs/pro/noarch $ which python /Users/shahab/anaconda3/bin/python – Sha2b Aug 24 '17 at 19:38
0

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)

Reddspark
  • 6,934
  • 9
  • 47
  • 64
  • The problem was [solved](https://stackoverflow.com/a/45916203/7175780) by changing the executables of the notebook. the problem was not the installation of packages but the change in the paths that the notebook used. – Sha2b Sep 10 '17 at 21:00