如何在python中导入Tensorflow库?

Dou*_*alu 2 python python-3.x anaconda tensorflow

一个非常基本的问题。

我正在尝试在Anaconda python(spyder)中安装tensorflow库。

import tf.contrib.keras.preprocessing
Run Code Online (Sandbox Code Playgroud)

它给了我错误,因为"No module found".我也尝试了导入tensorflow.contrib.keras.preprocessing

我也试过了 from tf.contrib.keras.preprocessing.text import Tokenizer。

这也行不通

但是我在tensorflow网站上对此进行了验证,并且它存在。到库的链接是https://www.tensorflow.org/api_docs/python/tf/contrib/keras/preprocessing。

我试图点和康达安装。但这也抛出了错误。

在anaconda提示符下,我输入了以下内容:

activate tensorflow 
pip install tf.contrib.keras.preprocessing
conda install tf.contrib.keras.preprocessing
Run Code Online (Sandbox Code Playgroud)

有什么我想念的,请纠正我。

Y0d*_*0da 5

您做错了,因为tf不是tensorflow模块名称,而是教程中的别名。

import tensorflow as tf
Run Code Online (Sandbox Code Playgroud)

因此,请尝试以下操作:

from tensorflow.contrib.keras.preprocessing.text import Tokenizer
Run Code Online (Sandbox Code Playgroud)

从您的评论看来,该模块可能未安装,因此您可以检查已安装软件包的列表:

conda list
Run Code Online (Sandbox Code Playgroud)

如果不存在,请使用安装pip。遵循文档。