0

I am using Ubuntu 14.04. I am trying to use the tensorflow module, but although I have it installed, and installed it the same way I would install any other pkg or module, it is not recognized by python as being installed. Even though pip says it is installed... I am not sure what the hell is going on.

See for yourselves:

$ sudo pip install tensorflow
The directory '/home/tex/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/tex/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: tensorflow in /home/tex/.local/lib/python2.7/site-packages
Requirement already satisfied: six>=1.10.0 in /home/tex/.local/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied: markdown>=2.6.8 in /home/tex/.local/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied: bleach==1.5.0 in /home/tex/.local/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied: backports.weakref==1.0rc1 in /home/tex/.local/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied: html5lib==0.9999999 in /home/tex/.local/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied: werkzeug>=0.11.10 in /home/tex/.local/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied: mock>=2.0.0 in /home/tex/.local/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied: numpy>=1.11.0 in /home/tex/.local/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied: wheel in /usr/lib/python2.7/dist-packages (from tensorflow)
Requirement already satisfied: protobuf>=3.2.0 in /home/tex/.local/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied: funcsigs>=1; python_version < "3.3" in /home/tex/.local/lib/python2.7/site-packages (from mock>=2.0.0->tensorflow)
Requirement already satisfied: pbr>=0.11 in /home/tex/.local/lib/python2.7/site-packages (from mock>=2.0.0->tensorflow)
Requirement already satisfied: setuptools in /home/tex/.local/lib/python2.7/site-packages (from protobuf>=3.2.0->tensorflow)

But when I try to import it from python, this is what I get:

$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow

Why is this happening? I am also having a much weirder error. I am using flask on a virtualenv. When I start my virtualenv, it does not recognize that numpy is installed, even though it is, and it is recognized outside the virtualenv. Let me show you:

(venv)tex@ubuntu:~/scratch/ilya/mock$ sudo pip install numpy
The directory '/home/tex/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/tex/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: numpy in /home/tex/.local/lib/python2.7/site-packages
(venv)tex@ubuntu:~/scratch/ilya/mock$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy

However, when I exit the virtualenv...

tex@ubuntu:~/scratch/ilya/mock$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>

⊙_ʘ

Edit: not a possible duplicate because the link posted doesn't address the same issues... so... basically, a completely different question.

Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
John Lexus
  • 3,576
  • 3
  • 15
  • 33
  • 1
    Possible duplicate of [Why i can't do some things without sudo using Python and pip?](https://stackoverflow.com/questions/33922240/why-i-cant-do-some-things-without-sudo-using-python-and-pip) – phd Aug 22 '17 at 20:43
  • @phd No, I don't even know why you think so, not even somewhat close – John Lexus Aug 22 '17 at 20:49
  • The answer there clearly explains when you should use `sudo` and when `virtualenv`. You can easily get (and you must have googled) that `sudo` in a virtual environments is meaningless if not evil. You mentioned problems accessing python modules inside and outside virtual environments — but that exactly what virtual environments do: protect inside libraries from the outside. – phd Aug 22 '17 at 20:54

1 Answers1

1

Just because you source your virtualenv, this doesn't mean the 'pip' command will reference the pip library of the virtualenv. The 'pip' command is more than likely still linked to your default python interpreter.

You can try the following to get it working:

Start by uninstalling both modules:

[root@server] sudo pip uninstall tensorflow
[root@server] sudo pip uninstall numpy

Then source your virtualenv:

[root@server] source ~/venv/activate

Then install the modules using pip whilst explicitly calling the python command:

(venv)[root@server] python -m pip install tensorflow
(venv)[root@server] python -m pip install numpy

Then see if they are available:

(venv)[root@server] python
>> import numpy
Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65