Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow import error: No module named 'tensorflow'

I installed TensorFlow on my Windows Python 3.5 Anaconda environment The validation was successful (with a warning)

(tensorflow) C:\>python 

Python 3.5.3 |Intel Corporation| (default, Apr 27 2017, 17:03:30) [MSC v.1900 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information. Intel(R) Distribution for Python is brought to you by Intel Corporation. Please check out: https://software.intel.com/en-us/python-distribution

>>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() 

2017-10-04 11:06:13.569696: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

>>> print(sess.run(hello)) 

b'Hello, TensorFlow!'

However, when I attempt to import it into my python code

from __future__ import print_function, division import numpy as np import os import matplotlib import tensorflow as tf 

I get this error

ImportError: No module named 'tensorflow'

This is the location of the tensorflow package on my C drive

C:\Users\myname\Anaconda2\envs\tensorflow\Lib\site-packages\tensorflow 

When I go to Anaconda Navigator, it seems I have to choose either root, Python35, or Tensorflow. It looks like the Tensorflow environment includes Python35.

Anaconda Navigator launcher had to be reinstalled recently, possibly due to the Tensorflow installation. Maybe if there were another way to set the environment to Tensorflow within Anaconda /Spyder IDE other than the Navigator it might help

Method of installing tensorflow

conda create --name tensorflow python=3.5;  pip install --ignore-installed --upgrade tensorflow  

I did try: uninstalling and reinstalling protobuf, as suggesed by some blogs

I see another SO user asked the same question in March, received no reply

like image 869
Lcat Avatar asked Oct 04 '17 15:10

Lcat


People also ask

How do I fix No module named in tensorflow?

The Python "ModuleNotFoundError: No module named 'tensorflow'" occurs when we forget to install the tensorflow module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install tensorflow command.


1 Answers

The reason Python 3.5 environment is unable to import Tensorflow is that Anaconda does not store the tensorflow package in the same environment.

One solution is to create a new separate environment in Anaconda dedicated to TensorFlow with its own Spyder

conda create -n newenvt anaconda python=3.5 activate newenvt 

and then install tensorflow into newenvt

I found this primer helpful

like image 125
Lcat Avatar answered Sep 17 '22 13:09

Lcat