I have installed Tensorflow and Keras by Anaconda (on Windows 10), I have created an environment where I am using Python 3.5.2 (the original one in Anaconda was Python 3.6).
When I try to execute import keras as ks
, I get ModuleNotFoundError: No module named 'keras'
.
I have tried to solve this issue by sys.path.append(C:\\Users\\ ... \\Anaconda3\\python.exe)
with both notebook and console, but I continue to get the same error.
How could I solve this issue?
If you are a windows/mac user who are working on Jupyter notebook “pip install keras” doesn't help you .Try the below steps.It was solved for me 1. In command prompt navigate to the “site packages” directory of your anaconda installed. 2. Now use “conda install tensorflow” and after “conda install keras” 3. Re-start your Jupyter notebook and run the packages.
I have realized that I had two different Jupyter's directories, so I have manually deleted one on them. Finally, I have reinstalled Anaconda. Now Keras works properly.
Please try the following:
Run these in the jupyter notebook cell:
It may not be pointing to your virtual environment but to the root
The fix is to install the jupyter notebook from inside your virtual environment
Now you can import tensorflow or keras
Jupyter uses iPython under the hood, for python. So when you install Jupyter, it will also install iPython. There was one issue when I installed keras and Jupyter: I already have iPython installed in my root Anaconda environment. This is the output after I install Jupyter and keras:
Notice that even though I am inside my conda environment, it still looks for libraries in my root conda environment. And of course keras isn't there.
The step to fix is simply re-activate my environment, with:
source deactivate && source activate [my_env]
Then I am using a correct ipython:
(Not an answer but some troubleshooting hints)
sys.path is not the path to your Python executable, but the path to the libraries.
You might try to uninstall Jupiter and install it again, and hope that the new installation picks up the packages which are already installed. What could happen is that you have more than one Python installation and different libraries being installed to the different places. sys.path, when requested from different environments, might give you a hint if that's true.
The kernel in console and jupyter are not necessarily the same, and the problem might be that you are not on python 3.5.
should tell you what is running in the console, and in jupyter you should see it as a choice on starting a new notebook. For me, the information in
Using both Python 2.x and Python 3.x in IPython Notebook
was very helpful.