Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named tensorflow in jupyter

I have some imports in my jupyter notebook and among them is tensorflow:

ImportError                               Traceback (most recent call last) <ipython-input-2-482704985f85> in <module>()       4 import numpy as np       5 import six.moves.copyreg as copyreg ----> 6 import tensorflow as tf       7 from six.moves import cPickle as pickle       8 from six.moves import range  ImportError: No module named tensorflow 

I have it on my computer, in a special enviroment and all connected stuff also:

Requirement already satisfied (use --upgrade to upgrade): tensorflow in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages Requirement already satisfied (use --upgrade to upgrade): six>=1.10.0 in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages (from tensorflow) Requirement already satisfied (use --upgrade to upgrade): protobuf==3.0.0b2 in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages (from tensorflow) Requirement already satisfied (use --upgrade to upgrade): numpy>=1.10.1 in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages (from tensorflow) Requirement already satisfied (use --upgrade to upgrade): wheel in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages (from tensorflow) Requirement already satisfied (use --upgrade to upgrade): setuptools in ./setuptools-23.0.0-py2.7.egg (from protobuf==3.0.0b2->tensorflow) 

I can import tensorflow on my computer:

>>> import tensorflow as tf >>>  

So I'm confused why this is another situation in notebook?

like image 401
Skotti Bendler Avatar asked Jul 06 '16 09:07

Skotti Bendler


People also ask

How do I fix No module named in tensorflow?

The Python "ModuleNotFoundError: No module named 'tensorflow'" occurs when we forget to install the tensorflow module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install tensorflow command.


2 Answers

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 
like image 62
Idel Pivnitskiy Avatar answered Sep 26 '22 14:09

Idel Pivnitskiy


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  
like image 22
alif Avatar answered Sep 24 '22 14:09

alif