Tensorflow环境配置

Tensorflow 环境配置

环境配置

Python环境为3.7 ,最新版本不适配

使用anaconda,安装时添加至系统path

  1. 使用Anconada Prompt 输入conda create -n TF2.1 python=3.7创建环境

  2. 接着输入conda activate TF2.1 进入环境

  3. 若是NVDIA显卡 可使用conda install cudatoolkit=10.1 和conda install cudnn 安装 显卡加速 和 英伟达深度学习包

  4. 最后使用pip install tensorflow==2.1 安装tensorflow(若下载慢可加上-i https://pypi.tuna.tsinghua.edu.cn/simple 镜像)

  5. 验证安装是否成功,紧接着输入python

  6. 输入import tensorflow as tf ,输入

    1
    print(tf.__version__)

    若出现‘’2.1.0“则安装成功

  7. 配置pycharm集成式开发环境创建新项目使用刚配置的anconda环境

  8. 在此项目内运行一下代码后

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    import tensorflow as tf

    tensorflow_version = tf.__version__
    gpu_available = tf.test.is_gpu_available()

    print("tensorflow version:", tensorflow_version, "\tGPU available:", gpu_available)

    a = tf.constant([1.0, 2.0], name="a")
    b = tf.constant([1.0, 2.0], name="b")
    result = tf.add(a, b, name="add")
    print(result)

    结果为则开发环境安装成功