ubuntu 18.04安装tensorflow (CPU)

2023-02-15,,,,

在已经安装anaconda环境及pip之后。

    添加并设置pip配置文件:
mkdir ~/.pip
vim ~/.pip/pip.conf

pip.conf文件内容:

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
    安装tensorflow
# pip install tensorflow
# pip uninstall tensorflow
pip install tensorflow-cpu
    测试tensorflow
#!/usr/local/bin/python3
import tensorflow as tf hello = tf.constant('Hello, tf!')
sess = tf.Session()
print (sess.run(hello)) a = tf.constant(10)
b = tf.constant(32)
print (sess.run(a+b)) matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul(matrix1, matrix2)
result = (sess.run(product))
print (result) sess.close()

参考:

Mac和Ubuntu下修改pip源和TensorFlow(CPU)安装

ubuntu 18.04安装tensorflow (CPU)的相关教程结束。

《ubuntu 18.04安装tensorflow (CPU).doc》

下载本文的Word格式文档,以方便收藏与打印。