tensorflow环境搭建

gpu版本的tensorflow环境搭建

逃避的人

2019.03.03 13:31:58字数 337阅读 187

anaconda

首先安装anaconda,官网下载,直接安装,可参考网上教程

python虚拟环境创建

conda create -n tensorflow python=3.7 ipykernel

执行上述命令创建名字为tensorflow的环境,指定该环境python版本为3.7;安装ipykernel包,便于后续jupyter的使用;

conda env list 

查看所有环境,带*表示当前**环境,默认为base环境

conda activate tensorflow

**tensorflow环境

conda deactivate tensorflow

关闭tensorflow环境,回到base环境

tensorflow安装

conda search ‘*tensorflow*’

conda search ‘*tensorflow-gpu*’

搜索tensorflow版本

conda install -n tensorflow tensorflow-gpu=1.12.0

指定为tensorflow环境安装1.12.0的gpu版本的tensorflow

import tensorflow as tf

hello = tf.constant('Hello, TensorFlow!')

sess = tf.Session()

print sess.run(hello)

验证是否安装成功

jupyter notebook使用

jupyter notebook

启动jupyter notebook,点击新建,选择kernel(上面conda create时安装ipykernel会自动创建和该虚拟环境关联的kernel),即可创建并在页面上运行python代码。若kernel不是指定环境的,会无法import该环境的module。

若创建环境时忘记安装ipykernel,可在**环境后安装

conda activate tensorflow

conda install ipykernel

python -m ipykernel install --name tensorflow

最后一行为创建名为tersorflow的kernel,重启jupyter notebook后即可看见新建的kernel。

相关文章:

  • 2021-12-03
  • 2021-11-05
  • 2021-07-23
  • 2021-07-09
  • 2022-01-14
  • 2021-10-18
  • 2021-05-24
  • 2021-05-17
猜你喜欢
  • 2021-08-22
  • 2021-05-16
  • 2021-09-24
  • 2022-01-22
  • 2021-04-23
  • 2021-07-12
  • 2021-03-28
相关资源
相似解决方案