X.Zoe
X.Zoe

Reputation: 23

ImportError: No module named tensorflow, but tensorflow does exist

I installed tensorflow with virtualenv on linux. There is a tensorflow package under sitepackage folder, but when I run the demo downloaded from Github, it shows:

(tensorflow) idc@idc-Hi-Fi-Z77X:~/tensorflow$ sudo python CNN_sentence_tensorflow-master/sentence_classfier_with_tensorflow.py
Traceback (most recent call last):
  File "CNN_sentence_tensorflowmaster/sentence_classfier_with_tensorflow.py", line 13, in <module>
import tensorflow as tf
ImportError: No module named tensorflow

I do this at interface. It's ok:

(tensorflow) idc@idc-Hi-Fi-Z77X:~/tensorflow/multi-class-text-classification-cnn-master$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import tensorflow as tf
>>>    

Upvotes: 2

Views: 1779

Answers (2)

McGrady
McGrady

Reputation: 11487

Because sudo python basically means run python as some other user (root by default). That user may have a different set of environment variables, including $PATH.

Some of linux distributions use older Python version for root user,like centos.Have a look at the outputs of which python and sudo which python, you'll see they might be different.

[~]$ which python
/usr/local/bin/python
[~]$ sudo which python
/usr/bin/python

Maybe you don't need to use sudo,or you can set permissions to all files and folders by using chmod -R 755 /folder.

Hope this helps.

Upvotes: 0

Reynard Asis
Reynard Asis

Reputation: 483

you are using sudo python CNN_sentence_tensorflow-master/sentence_classfier_with_tensorflow.py

if you use sudo i think it will use your main python version not the one in your virtualenv

Upvotes: 1

Related Questions