No module named tensor flow — iPython notebook

2020-04-08 06:57发布

I understand this may be an old question, but still I cannot find solution from off-the-shelf Q$A. Here is the problem:

I am following Udacity "Machine Learning" and its assignments, and need use iPythonNotebook & tensorflow. Details : https://github.com/Omarito2412/udacity-deeplearning

Assignment2 requires tensorflow. BTW, I already installed Anaconda, already made tensorflow working on Pycharm on the same computer which is Macbook, but do not know how to make it work on iPythonNotebook environment.

The codes are quite simple, as follows:

import numpy as np
import tensorflow as tf
from six.moves import cPickle as pickle
from six.moves import range

and the error message is as follows:

ImportError                               Traceback (most recent call last)
<ipython-input-1-0970743dd90d> in <module>()
      2 # before proceeding further.
      3 import numpy as np
----> 4 import tensorflow as tf
      5 from six.moves import cPickle as pickle
      6 from six.moves import range

ImportError: No module named tensorflow

Thanks. Any suggestions ?

PS: I have this problem on two MacBooks, and both MacBooks run Pycharm+tensorflow well.

5条回答
Emotional °昔
2楼-- · 2020-04-08 07:27

You should deactivate and re-activate the environment

source deactivate tensorflow
source activate tensorflow
查看更多
我命由我不由天
3楼-- · 2020-04-08 07:39

i have missed tensorflow install (3) number below the list.. now i have solved

  1. for anaconda install

  2. for enviroment install https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation

  3. for tensorflow install https://github.com/conda-forge/tensorflow-feedstock

查看更多
走好不送
4楼-- · 2020-04-08 07:43

After I tried Anaconda-installation (I was using the other installation methods, which are all shown in the link below) https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation It worked ...

Further, on terminal activate tensorflow

>>> source activate tensorflow

before open iPython Notebook

>>> ipython notebook

At last, I have to restart my macbook to make it work....

查看更多
甜甜的少女心
5楼-- · 2020-04-08 07:46

More than likely either Tensorflow is not installed in the right Python environment of Conda or not installed at all. Follow the below steps:

$ conda create -n tensorflow python=3.5

Once that is done, need to activate that as below:

$ source activate tensorflow

Then when you open IPython Notebook or Spyder, it will recognize the Tensorflow.

查看更多
一夜七次
6楼-- · 2020-04-08 07:51

This is likely due to an anemic environment variable, one of the library path class. I don't know how iPythonNotebook denotes the libraries it will search for files (say, $LD_LIBRARY_PATH), but I believe that you have to find it (a list of paths to libraries) and add the root directory of TensorFlow.

查看更多
登录 后发表回答