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

点击创建环境

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

python版本用3.6就可以

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

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

环境配置好后安装pycharm

选择file>>settings>>project>>project interpreter

选择add local python interpreter

添加刚刚创建环境的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

安装成功

  • 12
    点赞
  • 61
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
使用Anaconda3和PyCharm配置TensorFlow-GPU 2.4.0深度学习环境是一个相对简单的过程,我将分享我的经验。 首先,你需要确保已经在计算机上安装了Anaconda3和PyCharm。然后,你可以按照以下步骤进行配置: 1. 打开Anaconda Navigator,并创建一个新的虚拟环境。你可以选择Python 3.7版本,并命名环境为"tensorflow-gpu"。 2. 激活新环境后,在终端或命令提示符下输入以下命令来安装TensorFlow-GPU 2.4.0: ``` conda install tensorflow-gpu=2.4.0 ``` 3. 安装完成后,你可以通过以下命令验证TensorFlow-GPU是否正确安装: ``` python -c "import tensorflow as tf; print(tf.__version__)" ``` 如果输出显示为2.4.0,则说明TensorFlow-GPU已经成功安装。 4. 接下来,在PyCharm中打开一个新的项目。在项目设置中,选择已创建的虚拟环境"tensorflow-gpu"作为项目的Python解释器。 5. 在PyCharm的终端中,使用以下命令来安装GPU版本的TensorFlow依赖项: ``` pip install tensorflow-gpu==2.4.0 ``` 6. 安装完成后,你可以编写和运行使用TensorFlow-GPU的代码了。 在配置过程中,可能会遇到一些问题。例如,TensorFlow-GPU要求计算机上安装了适当的显卡驱动程序,并且CUDA和cuDNN版本与TensorFlow-GPU的要求相匹配。此外,如果你在安装过程中遇到任何问题,可以尝试升级或降级AnacondaPyCharmTensorFlow-GPU版本,以找到兼容的组合。 总之,通过Anaconda3和PyCharm配置TensorFlow-GPU 2.4.0深度学习环境是一项相对简单的任务。如果按照上述步骤操作,你应该能够成功地设置和使用TensorFlow-GPU来进行深度学习任务。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值