我们在帮助客户搭建Drupal站点的时候,需要为Drupal站点添加一点智能化,比如自动分类,我们比较了多个AI框架,发现Google公司出品的tensorflow最能满足我们的需要。使用tensorflow训练出来模型,使用Drupal调用模型,实现自动分类。这个文档是我们整理的一个tensorflow的安装笔记。
https://www.anaconda.com/products/individual
下载最新版本anaconda集成环境
增加镜像,使用清华大学的
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
创建一个环境,python版本:3.8
conda create -n tensorflow python=3.8
安装成功:
执行命令:
activate tensorflow
pip install --upgrade --ignore-installed tensorflow
创建环境的时候,如果网络不通,可以采用科学上网的策略。
如果出现模块未找到,
在当前环境下面,安装,需要的依赖。
打开Anaconda Navigator
—>Environments
—>tensorflow
,选择Not installed
,找到iPython和Spyder以及jupyter并安装。
参考文章:
https://www.jianshu.com/p/52c6c9afe33e
使用root 默认的环境运行,
系统提示,AttributeError: module 'tensorflow' has no attribute 'Session'
原因是tensorflow的版本较高,默认移除了这个属性,可以使用兼容的办法:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant('Hello, TensorFlow!') #初始化一个TensorFlow的常量
sess = tf.compat.v1.Session() #启动一个会话
print(sess.run(hello))
执行官方给的第一个训练程序,顺利完成。