2

ModuleNotFoundError Traceback (most recent call last) in () 11 import numpy as np 12 ---> 13 import tensorflow as tf 14 15

ModuleNotFoundError: No module named 'tensorflow'

Richard Boire
  • 21
  • 1
  • 2

3 Answers3

2

I was looking for a similar issue (unable to import tensorflow in jupyter) and found that maybe most answers are outdated because now conda installs tf in its own environment.

The most useful thing I found is:

https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/

which explains in very few steps how to install tf or tf-gpu in its own environment.

Then my problem was that the jupyter notebook is in its own base environment, not in the tf-gpu environment. How to work with that from a jupyter notebook based on the base environment?

The solution comes from the very helpful answer from Nihal Sangeeth to this question

https://stackoverflow.com/questions/53004311/how-to-add-conda-environment-to-jupyter-lab

conda activate tf-gpu

(tf-gpu)$ conda install ipykernel

(tf-gpu)$ ipython kernel install --user --name=<any_name_you_like_for_kernel>

(tf-gpu)$ conda deactivate

Close and reopen your jupyter notebook. Then in your jupyter notebook you will find the option, under "kernel" of "change kernel". Change kernel to your newly created kernel and you will be able to import tensorflow as tf and go on from there.

Hope it helps somebody

Ivan
  • 759
  • 10
  • 18
1

You can use following commands to import by Anaconda prompt:

conda install tensorflow

it will download all tensorflow environment setup.

enter image description here

then you can check any where:

import tensorflow

enter image description here

0

This might occur from several issues

  • Is tensorflow installed ?
    • pip install --upgrade tensorflow
  • Are you sure you're in the same conda enviroment which has tensorflow isntalled ?

    • conda env list
           # conda environments:
            deep-learning            /Users/wassimseifeddine/anaconda/anaconda3/envs/deep-learning
            root                    /Users/wassimseifeddine/anaconda/anaconda3
      

try switching between this environments source activate <env-name> and trying pip freeze to chech if tensorflow is installed.

Wassim Seifeddine
  • 1,002
  • 12
  • 25