0

I'm trying to get some tensorflow code running inside of a Jupyter notebook that I have. I have the Python extension for IntelliJ Ultimate Edition, and have the notebook set up. I have some simple test code that I am trying to run:

import tensorflow as tf
print(tf.__version__)

When I run it inside of a .py file, I get the output that I am expecting (2.2.0). When I run it inside of a Jupyter Notebook, however, I get

ModuleNotFoundError Traceback (most recent call last)
<ipython-input-10-f83c6d50081b> in <module>
----> 1 import tensorflow as tf
  2 print(tf.__version__)

ModuleNotFoundError: No module named 'tensorflow'

It seems that the imports are not working inside of the Jupyter Notebook? Do I have to do any extra setup for the import statements to work? I have tensorflow installed in my system (I used pip), and I have tensorflow inside of my SDK Package list in IntelliJ.

hsz
  • 148,279
  • 62
  • 259
  • 315
  • is this jupyter notebook part of a conda installation? – Abhishek Malik Jul 27 '20 at 19:06
  • @AbhishekMalik No, I installed Jupyter using homebrew and have it running inside of my localhost. Connected to it using IntelliJ. – Sathvik Chinta Jul 27 '20 at 19:08
  • 1
    then it most probably is using a different python compiler... you need to check if your python command points to the same python version than the jupyter version. – Dorian Jul 27 '20 at 19:13
  • @Dorian I imported sys and used print(sys.version) in both the .py file and the jupyter notebook. Both say that they are using 3.8.5, and have the same timestamp on the install date. – Sathvik Chinta Jul 27 '20 at 19:17
  • What about a `!pip install tensorflow` ran in your notebook cell? – Adrien Pacifico Jul 27 '20 at 19:25

1 Answers1

2

Make sure you have the tensorflow module linked to the right python version on your computer. To be sure, you can install it from inside the notebook using:

# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install tensorflow
Dorian
  • 1,439
  • 1
  • 11
  • 26
  • 1
    I moved away from IDEs due to issues I have with installing and later importing packages into the codebase with them. I do truly prefer to create a virtual environment in the command line and edit with Atom, as it's just incredibly simple and it works perfectly fine. Unfortunate that the very applications designed to make it easier on us, in some ways can make it difficult for those who aren't yet acquainted with their nuances. – OakenDuck Jul 27 '20 at 20:37