0

Hello I'm a highschool student and I was given the task of making a CNN. I am not very familiar with this type of coding. Every time we run the code in Jupyter Notebook this error:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-9-7d4e1bb634e9> in <module>
      8 import matplotlib.pyplot as plt
      9 import numpy as np
---> 10 import tensorflow as tf
     11 
     12 # Allow image embeding in notebook

ModuleNotFoundError: No module named 'tensorflow'

I've put it under Python 3.6 like my prof suggested and I am using tensorflow 1.4, which is the version I must use. I'm also working on mac os. He also said we can't put tensorflow under a virtual environment or else the program won't work. If there is any way to fix this problem through the terminal or otherwise it would be highly appreciated. Thanks for the help. Edit: I am using jupyter notebook under anaconda. And Conda commands are not recognized for me.

  • if you have a virtual environment that has tensorflow is installed, you need to select the appropriate python kernel – snnguyen Feb 05 '20 at 22:40
  • If you're using conda environments, check out this answer https://stackoverflow.com/q/39604271/2662958 – snnguyen Feb 05 '20 at 22:52

2 Answers2

0

install Jupyter in user's local python library path

pip install --user jupyter

install python virtual environment to be used as a Jupyter kernel

virtualenv -p python3 tf-venv

activate the python virtual environment tf-venv

Note: this example was specific for tensorflow, but install as many as desired.

source tf-venv/bin/activate

install tf-venv specific python packages

pip install tensorflow

install ipykernel modlue

pip install ipykernel

install tf-venv as a Jupyer kernel

Note: this will install the tf-venv kernel into your user's python local libraries in ~/.local

  pip install -m ipykernel --user --name=tf-venv

deactivate your tf-venv virtual environment

deactivate

start jupyter notebook

jupyter notebook

enter image description here

Kristian
  • 482
  • 2
  • 8
0

The above answer did work for me except that last install command should be replaced with

python install -m ipykernel --user --name=tf-venv
awmleer
  • 1,658
  • 3
  • 13
  • 28