ubuntu 18.04安装tensorflow (CPU)

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

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

pip.conf文件内容:

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
  1. 安装tensorflow
# pip install tensorflow
# pip uninstall tensorflow
pip install tensorflow-cpu
  1. 测试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()

参考:

posted @ 2022-02-24 14:33  山岚2013  阅读(150)  评论(0编辑  收藏  举报