ubuntu装TensorFlow-GPU2.1.0
发布日期:2021-05-14 03:20:08 浏览次数:24 分类:精选文章

本文共 1390 字,大约阅读时间需要 4 分钟。

Ubuntu 安装TensorFlow-GPU 2.1.0 指南

在 Ubuntu 16.04 系统上安装TensorFlow-GPU 2.1.0 可能会遇到一系列问题。本文将详细介绍所需步骤,包括代码环境设置和TensorFlow的安装及配置。


一、 添加Anaconda下载源

由于网络限制,建议添加清华大学镜像源,确保Anaconda能够顺利下载所需文件。

执行以下命令以添加镜像源:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

验证是否成功添加源:

conda info

二、 创建并激活虚拟环境

创建一个基于 Python 2.7 的虚拟环境(与安装TensorFlow-GPU 2.1.0兼容)。

命令示例:

conda create -n py27_tf120 python=2.7

/',div>

激活虚拟环境
conda activate py27_tf120

'/


三、 安装TensorFlow-GPU 2.1.0

使用 conda Command Chart安装TensorFlow-GPU:

conda install tensorflow-gpu=2.1.0

安装过程中可能会自动升级 Python 至 3.7。如果需要保持 Python 2.7,可以在安装完成后手动降级:

pip install --user python=3.7

四、 测试安装

验证TensorFlow-GPU 是否成功安装。

测试TensorFlow 1.x版本:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

测试TensorFlow 2.x版本:

import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant('hello, tensorflow')
sess = tf.compat.v1.Session()
print(sess.run(hello))

五、 虚拟环境管理

移除TensorFlow包

conda remove -n py27_tf120 tensorflow-gpu=2.1.0

移除虚拟环境

conda remove -n py27_tf120 --all

检查包版本

conda search tensorflow-gpu

获取Python 二的路径

which python2

列出环境列表

conda env list

如以上步骤完成后,TensorFlow-GPU 2.1.0 应该已成功安装。


⚠️ 注意事项:安装过程中可能会升级系统软件,请确保系统稳定。

如有疑问,请连接社区讨论。

上一篇:Python2.7 使用pip命令报错 sys.stderr.write(f“ERROR: {exc}“)
下一篇:Ubuntu安装Anaconda3

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月26日 10时50分39秒