anaconda+pycharm配置tensorflow-GPU环境最简单方法

现在回头来看当时搭建环境水了点,更新一个在Windows上搭建tensorflow-gpu环境的方法,大概就用10分钟吧:

首先下载清华miniconda镜像,https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/ 

然后安装,安装好之后打开Anaconda Prompt,会出现终端界面,不要慌,终端界面很简单几乎不用敲指令,直接复制就可以。

首先对anaconda换源,这样可以加速环境安装速度,一条一条的复制下面的命令到终端中:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

复制入命令建立anaconda环境

conda create -n tensorflow python=3.6

这条指令创建了一条名字是tensorflow的环境,环境中安装python3.6

然后复制进入pip指令来更换pip源,同样是为了加快安装速度:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

这时你的pip就设置好了,pip相当于应用商城,需要安装什么直接用pip install +你想安装的包就可以了,在安装之前也可以用 pip search + 名字 来搜索包的信息。然后我们安装tensorflow-gpu

pip install tensorflow-gpu

如果没有安装cuda和cudnn的同学可以用conda指令来安装,conda就自动为你安装上了cuda和cudnn.

conda install tensorflow-gpu

现在你可以使用指令看看你的anaconda环境信息和位置

conda info -e

然后按文章最后的配置pycharm 环境就好了。


2018年开始学习tensorflow框架。买了块显卡1060 6G。装上了原生的ubuntu16.04。从安装显卡驱动到cuda和cudnn。无奈配置tensorflow环境一直报错。之后转回windows系统。试着继续用网上说的命令行配置,还查了tensorflow的官方文档。还是报错。

最后用最简单的anaconda navigator配置成功。前后不到2个小时。

下面说下步骤。

首先确定显卡

首先从官网https://www.anaconda.com/download/安装anaconda。版本最新的就可以。

安装完成后打开anaconda navigator

anaconda+pycharm配置tensorflow-GPU环境最简单方法_第1张图片

点击创建环境anaconda+pycharm配置tensorflow-GPU环境最简单方法_第2张图片

输入环境名称。(我这里使用tensorflow1,因为之前创建好tensorflow。之前没有创建过的可以用tensorflow)

python版本用3.6就可以

anaconda+pycharm配置tensorflow-GPU环境最简单方法_第3张图片

在package选项中选择Not install会列出所有未安装package

在菜单中找到tensorflow-gpu点击apply进行安装。安装的是1.1.0版本.

环境配置好后安装pycharm

选择file>>settings>>project>>project interpreteranaconda+pycharm配置tensorflow-GPU环境最简单方法_第4张图片

选择add local python interpreter

anaconda+pycharm配置tensorflow-GPU环境最简单方法_第5张图片

添加刚刚创建环境的python地址。

然后运行示例

 

import tensorflow as tf

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

sess = tf.Session()

print(sess.run(hello))

得到

 

C:\Users\Administrator\AppData\Local\conda\conda\envs\tensorflow\python.exe E:/tensorflow/test.py
2018-01-05 10:12:41.831346: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2018-01-05 10:12:41.831624: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2018-01-05 10:12:41.831897: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2018-01-05 10:12:41.832299: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-01-05 10:12:41.832653: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-01-05 10:12:41.832942: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-01-05 10:12:41.833232: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2018-01-05 10:12:41.833522: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2018-01-05 10:12:42.160935: I c:\l\work\tensorflow-1.1.0\tensorflow\core\common_runtime\gpu\gpu_device.cc:887] Found device 0 with properties: 
name: GeForce GTX 1060 6GB
major: 6 minor: 1 memoryClockRate (GHz) 1.7715
pciBusID 0000:01:00.0
Total memory: 6.00GiB
Free memory: 5.00GiB
2018-01-05 10:12:42.161316: I c:\l\work\tensorflow-1.1.0\tensorflow\core\common_runtime\gpu\gpu_device.cc:908] DMA: 0 
2018-01-05 10:12:42.161567: I c:\l\work\tensorflow-1.1.0\tensorflow\core\common_runtime\gpu\gpu_device.cc:918] 0:   Y 
2018-01-05 10:12:42.161762: I c:\l\work\tensorflow-1.1.0\tensorflow\core\common_runtime\gpu\gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0)
b'Hello, TensorFlow!'


Process finished with exit code 0

安装成功

你可能感兴趣的:(机器学习)