I have some imports in my jupyter notebook and among them is tensorflow:
ImportError Traceback (most recent call last)
Conda environment fetches the tensorflow package from the main system site-packages.
Step 1: Just deactivate conda environment
conda deactivate
pip install tensorflow
Step 2: Switch back to conda environment
conda activate YOUR_ENV_NAME
jupyter notebook
Step 3: Run the cell with import tensorflow
you should be able to import.
Thanks
If you installed a TensorFlow as it said in official documentation: https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html#overview
I mean creating an environment called tensorflow and tested your installation in python, but TensorFlow can not be imported in jupyter, you have to install jupyter in your tensorflow environment too:
conda install jupyter notebook
After that I run a jupyter and it can import TensorFlow too:
jupyter notebook
the problem may when the Jupyter notebook may launching from the default but for able to import tensorflow and keras libraries so you have to install jupyter notebook like what you have installed the libraries
pip install jupyter
I also had the same problem for a long time. I wanted to import tensorflow inside the jupyter notebook within windows 10. I followed all the instructions and commands that were suggested and it was not working from the command prompt. Finally, I tried this command with the Anaconda Prompt and it worked successfully. If you are using jupyter notebook within Anaconda then go goto the windows search terminal and type "Anaconda Prompt" and inside it type following command, It will install the tensorflow inside the jupyter notebook.
conda install -c conda-forge tensorflow
As suggested by @Jörg, if you have more than one kernel spec. You have to see the path it points to. In my case, it is actually the path that was to be corrected.
When I created TensorFlow
virtual env, the spec had the entry for python which was pointing to base
env. Thus by changing W:\\miniconda\\python.exe
to W:\\miniconda\\envs\\tensorflow\\python.exe
solved the problem.
So it is worth looking at your kernel spec. Delete that is not needed and keep those you want. Then look inside the JSON files where the path is given and change if needs be. I hope it helps.
Jupyter runs under the conda environment where as your tensorflow install lives outside conda. In order to install tensorflow under the conda virtual environment run the following command in your terminal:
conda install -c conda-forge tensorflow