---
title: "Tensorflow初探"
author: "7wolfs"
date: "2019-12-07T19:10:44Z"
tags: []
categories: ["互联网"]
slug: "tensorflow"
draft: false
lastmod: "2019-12-07T19:10:44Z"
id: 2510868
url: "https://7wolfs.iteye.com/blog/2510868"
---

1、安装 tensorflow
Pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
安装时，为了加快下载资源速度，使用 i 参数，选择了国内镜像站点。

2、用helloworld代码tensorflow是否安装成功

```java

import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant('Hello, TensorFlow!')
sess = tf.compat.v1.Session()
print(sess.run(hello))

```

说明：
由于tf.Session()是tf1里的写法，在tf2里已经没有该方法，需要使用兼容写法来调用，用法在示例代码中已演示。

备注：
如果使用辅助工具Anaconda，可以在国内镜像资源站点上下载。
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.0.0-Windows-x86_64.exe

参考：
https://stackoverflow.com/questions/55142951/tensorflow-2-0-attributeerror-module-tensorflow-has-no-attribute-session
https://www.jianshu.com/p/e2dd167d2892