缺少 Tensorflow 和 Numpy

Tensorflow and Numpy missing

我正在使用 Ubuntu 14.04。我正在尝试使用 tensorflow 模块,但尽管我安装了它,并且安装方式与安装任何其他 pkg 或模块的方式相同,但 python 无法识别它是否已安装。尽管 pip 说它已安装...我不确定到底发生了什么。

自己看:

$ 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)

但是当我尝试从 python 导入它时,我得到的是:

$ 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

为什么会这样?我也有一个更奇怪的错误。我在 virtualenv 上使用烧瓶。当我启动我的 virtualenv 时,它无法识别安装了 numpy,即使它是,并且在 virtualenv 外部 被识别。让我告诉你:

(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

但是,当我退出 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
>>>

⊙_ʘ

编辑:不可能重复,因为发布的 link 没有解决相同的问题...所以...基本上,一个完全不同的问题。

仅仅因为您获取了 virtualenv,这并不意味着 'pip' 命令将引用 virtualenv 的 pip 库。 'pip' 命令很可能仍然链接到您的默认 python 解释器。

您可以尝试以下方法使其正常工作:

首先卸载两个模块:

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

然后获取你的虚拟环境:

[root@server] source ~/venv/activate

然后使用 pip 安装模块,同时显式调用 python 命令:

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

然后看看有没有空:

(venv)[root@server] python
>> import numpy