日期:2023-06-05  浏览次数:91 次

使用原生pip安装

如果您的机器上没有安装以下版本的Python,请立刻安装:

打开Cmd命令终端,开始安装 TensorFlow。然后在终端上运行正确的 pip3 安装命令。 安装仅支持 CPU 版本的 TensorFlow,请输入下面的命令:
C:\> pip3 install --upgrade tensorflow

可使用阿里云国内镜像快速安装:pip3 install -i http://mirrors.aliyun.com/pypi/simple/ --upgrade tensorflow

安装 GPU 版本的 TensorFlow,请输入下面的命令:
C:\> pip3 install --upgrade tensorflow-gpu

 

安装验证

C:\Users\Administrator>python
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

在 python 交互 shell 中输入下列代码:

import tensorflow as tf

# 创建图(Graph)
graph = tf.compat.v1.Graph()
with graph.as_default():
    hello = tf.constant('Hello, TensorFlow!')

# 创建会话(Session)并在会话中运行图中的操作
with tf.compat.v1.Session(graph=graph) as sess:
    print(sess.run(hello))

 

如果系统的输出如下所示,那就说明您可以开始在上面撰写 TensorFlow 的程序了:

Hello, TensorFlow!

2023-06-05 10:48:05.168560: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:357] MLIR V1 optimization pass is not enabled b'Hello, TensorFlow!'

如果系统输出了一个错误信息而不是一个打招呼提示,请查看常见安装问题

如果你是机器学习的新手,我们推荐以下内容:

Premade Estimators