我的电脑win10,anaconda3,默认python3.6
第一,请先确认已经安装anaconda,并勾选python3.6,添加进环境变量。(anaconda的安装就像普通软件一样,网上有很多,请自己百度一下)
第二,打开anaconda prompt

我平时用pycharm编程,为了节约空间,把spyder等工具都卸载了。
第三,输入清华大学的镜像(anaconda prompt),这样下载会快一点,否则默认连接的是外国网站,下载极慢。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
第四,在anaconda prompt中,再创建一个python3.5的环境,可以随意命名,这里为了方便识别,命名为tensorflow。
conda create -n tensorflow python=3.5
输入完命令之后会有一个安装过程。
第五,上一步的安装过程完毕之后,在开始菜单打开anaconda软件

可以看到,environment里面多了TensorFlow

第六,再次回到anaconda prompt启动TensorFlow环境
activate tensorflow

关闭tensorflow时,命令为
deactivate
第七,安装CPU版本的tensorflow
pip install --upgrade --ignore-installed tensorflow
出现success就表示安装成功。安装需要一些时间。
第八,在anaconda prompt测试tensorflow安装成功
启动python,输入测试代码
python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

运行成功,表示安装成功。
第九,因为平时使用pycharm编程,因此,想在pycharm中引入tensorflow。
pycharm中使用的是原先anaconda中自带的默认的python3.6

file----setting------Project Interpreter--------选择你的tensorflow的工程----选择你的对应版本的python


如果没有,选择showall------加号添加



确认添加后,出现了tensorflow
第十,新建python文件,编写测试代码

运行成功
网友评论