Skip to content

Cannot import tensorflow under python #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sunformoon opened this issue Dec 29, 2015 · 21 comments
Closed

Cannot import tensorflow under python #647

sunformoon opened this issue Dec 29, 2015 · 21 comments

Comments

@sunformoon
Copy link

Hi all, I first successfully installed the tensorflow following the instructions of "Pip Installation". However, I couldn't import tensorflow in Python. Thanks a lot!!

The error comes like this:

zhuotun@sunformoon:~$ python
Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec 6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org

import tensorflow as tf
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named tensorflow

I double check that I have installed successfully the tensorflow by re-installing the tensorflow as following:

zhuotun@sunformoon:~$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.6.0-cp27-none-linux_x86_64.whl
[sudo] password for zhuotun:
Downloading/unpacking https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.6.0-cp27-none-linux_x86_64.whl
Downloading tensorflow-0.6.0-cp27-none-linux_x86_64.whl (11.4MB): 11.4MB downloaded
Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.6.0)
Requirement already up-to-date: protobuf==3.0.0a3 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.6.0)
Requirement already up-to-date: wheel in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.6.0)
Requirement already up-to-date: numpy>=1.8.2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.6.0)
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf==3.0.0a3->tensorflow==0.6.0)
Installing collected packages: tensorflow
Successfully installed tensorflow

@mrry
Copy link
Contributor

mrry commented Dec 29, 2015

It looks (from your reported output) like this is an Anaconda issue. From what I can tell, the recommended way to install using Anaconda is to do the following:

$ pip install virtualenv
$ conda create --name=tensorflow_env python=2.7
$ source activate tensorenv
$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.6.0-cp34-none-linux_x86_64.whl

@sunformoon
Copy link
Author

Hi Derek,

Thanks a lot for your reply.

Based on your suggestion, I successfully installed a virtualenv of tensorflow using the following:

$ conda install virtualenv # suggested by the output of terminal not using pip install
$ conda create --name=tensorflow_env python=2.7
$ source activate tensorflow_env
$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl # the code you provided is for the python 3

Then, I tested the installation using the mnist demo. It worked! Cool!

@mrry
Copy link
Contributor

mrry commented Dec 30, 2015

Glad to hear it worked! One minor suggestion: sorry for the wrong link, but you should probably install from the following link to get the latest (0.6.0) version of TensorFlow:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.6.0-cp27-none-linux_x86_64.whl

@mrry mrry closed this as completed Dec 30, 2015
@osdf
Copy link

osdf commented Feb 1, 2016

Just to add to this issue: The original problem existed, because a sudo was used before pip, with you having a local anaconda installation. So the sudo's pip led to the system wide default pip, which installed tensorflow not into your local anaconda site-packages and hence it couldn't be found.

@parthpankajtiwary
Copy link

Hey osdf,

           Your comment proved to be a life saver, I was actually committing the mistake you just mentioned and was trying to access tensorflow from inside the environment. Removed sudo and it worked like magic. Thanks a lot for this comment.

Best,
Parth

@Svikashini
Copy link

Svikashini commented May 4, 2016

Hi all,

The above given suggestion is fr installing tensorflow in linux under conda environment. I am trying to install it on windows environment. Kindly help

I tried
conda install --channel https://anaconda.org/jjhelmus/tensorflow tensorflow

@ricoms
Copy link

ricoms commented Aug 30, 2016

I had the same problem as sunformoon and mrry's comment solved it.

I followed the online tutorial for TensorFlow ( https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html#test-the-tensorflow-installation ) on installing tensorflow on a virtualenv when I got the problem

@ahx-code
Copy link

@mrry

For Ubuntu 64 bit CPU Only :
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc1-cp27-none-linux_x86_64.whl

$ pip install virtualenv
$ conda create --name=tensorflow_env python=2.7
$ source activate tensorenv
$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc1-cp27-none-linux_x86_64.whl

For more and different binary versions :
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md

@shravankgit
Copy link

To me
i am using python3, but in terminal i was writing like python
that'why it is giving error[ImportError: No module named tensorflow] to me

@raheel78
Copy link

I have installed tensorflow on my Mac using simple pip command (e.g. pip install tensorflow). Now I am trying to test the setup by invoking python from command line and getting the same error:

$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow

Please help, what might be wrong here?

@raheel78
Copy link

I just tried doing the same thing by invoking python3 from command line instead of python and now the import tensorflow worked smoothly. What does that mean? Tensorflow has no compatibility with python 2.7 or 2.8??

@12343954
Copy link

12343954 commented Apr 5, 2017

$ cd /path/to/tensorflow/bin
$ source activate tensorflow
$ python

>>> import tensorflow as tf
>>> print(tf.__version__)
1.0.1

done!

@BIRlz
Copy link

BIRlz commented Jun 1, 2017

how can i use tensorflow in pypy? help!!!

@prasadheeramani
Copy link

@AhmetTavli
followed your procedure
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named tensorflow

tarasglek pushed a commit to tarasglek/tensorflow that referenced this issue Jun 20, 2017
@bwanglzu
Copy link

bwanglzu commented Jul 3, 2017

In case of you've validated tensorflow was corrected installed with terminal, while this error triggered in Ipython notebook, their might be a difference between your local python and ipython version, try this:

# in terminal
import sys
print (sys.version)
# in my case output is 2.7.9
# in notebook
import sys
print (sys.version)
# in my case output is 2.7.10

To solve, look at this.

@HRadmard
Copy link

I solve the problem by following steps (in Windows) this fix the problem in pycharm:
1- Run Anaconda prompt
2- Activate root (>activate root)
3- pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl
Finish!

@askari01
Copy link

askari01 commented Aug 21, 2017

I am using mac,
I have tensorflow being shown at pip3 show tensorflow but when I try to compile a .py file it says

ModuleNotFoundError: No module named 'tensorflow'

I used conda install as an alternate to solve the problem.

@ebonat
Copy link

ebonat commented Sep 8, 2017

I updated tensorflow from 1.1.0 to 1.3.0 using the wheel file: tensorflow-1.3.0-cp35-cp35m-win_amd64.whl and in the line:

import tensorflow as tf

I got the following error:

from numpy.core.multiarray import c_einsum
ImportError: cannot import name 'c_einsum'

Any help?

@techbot123
Copy link

Always activate the tensorflow environment (activate tensorflow) in the Anaconda prompt window before using tensorflow.

@cjcandctr
Copy link

I have the same issue on my windows box. like osdf commented on Feb 2, 2016, I run anaconda prompt as administrator, then system can find the tensorflow I installed.
BTW, I was using Console2.

@TrushitPatel
Copy link

first step is to ACTIVATE tensorflow
it can be done by firing these commands
"cd tensorflow/bin"
"source activate tensorflow"

and that should do allow you to import tensorflow.

particularly in my case,
next few steps are...

now go to the folder where premade_estimator resides
"cd models/samples/core/get_started/"
now run premade_estimator.py file by typing this command,
"python premade_estimator.py".

WORKED!!

darkbuck pushed a commit to darkbuck/tensorflow that referenced this issue Jan 23, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…pstream-zyin_remove_contrib_targets

Removing contrib code base and targets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests