ubuntu 18.04安装tensorflow (CPU)
阅读原文时间:2023年07月08日阅读:3

在已经安装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

  2. 测试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()

参考: