3

In anaconda prompt I was able to import tensorflow, but I can't import tensorflow in jupyterlab.

I downloaded anaconda today and opened anaconda prompt. Then I did

   python -m pip install --upgrade pip

.

   conda create -n tensorflow python=3.6

.

   activate tensorflow

.

   pip install tensorflow

.

   python

.

   import tensorflow as tf

.

   tf.__version__

and in the process there wasn't any error.

So I opend up jupyterlab and wrote

 import tensorflow as tf

but it didn't work.

In anaconda prompt I was able to import tensorflow like the code below.

 (base) C:\Users\SuperNoteJ>activate tensorflow

 (tensorflow) C:\Users\SuperNoteJ>python
 Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 18:50:55) [MSC v.1915 64 bit (AMD64)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import tensorflow as tf
 >>> tf.__version__
 '1.12.0'
 >>>

But when I opened anaconda navigator and launched jupyterlab(using base) I can't import tensorflow. The below code is the error code on jupyterlab.

 import tensorflow as tf
 -----------------------------------------------------------------------
 ModuleNotFoundError                       Traceback (most recent call last)
 <ipython-input-1-64156d691fe5> in <module>
 ----> 1 import tensorflow as tf

 ModuleNotFoundError: No module named 'tensorflow'
손진아
  • 31
  • 2

1 Answers1

1

I believe the reason why you could not import tensorflow was because you were not in the right environment. If tensorflow is installed inside the "tensorflow" environnment, you need to either lauch jupyter lab from that environment or to choose a kernel in that environment in jupyter lab.

If you're interested in the latter, I would refer to this topic (https://stackoverflow.com/a/53546634/10511793) on how to use another environment from jupyter lab launched in the base environment.

Statistic Dean
  • 4,861
  • 7
  • 22
  • 46