Win10下用Anaconda3安装TensorFlow和pytorch(python3.5)

1、安装Anaconda3。

Anaconda默认Python3.6,由于TensorFlow需要Python3.5,因此需要在root环境下更改Python版本。

2、添加镜像源。

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

3、安装Python3.5。

conda install python=3.5

等一会。

4、升级pip。直接用pip安装TensorFlow会出错。

使用管理员权限打开Anaconda Prompt

pip install --upgrade pip

关闭Anaconda Prompt,重新打开。

5、安装tensorflow。(CPU版本)

pip install --upgrade --ignore -installed tensorflow  

6、测试tensorflow。

spyder

在Spyder中输入:

import tensorflow as tf  
hello = tf.constant('Hello, TensorFlow!')  
sess = tf.Session()  
print(sess.run(hello))  

7、安装pytorch。

先安装

conda install numpy mkl cffi

或者需要升级mkl库

pip install mkl
pip install mkl --upgrade

或者

conda install mkl
conda update mkl

如果想要更新所有库

conda update --all

安装pytorch。(CPU版本)
链接: https://pan.baidu.com/s/10K8x6n2a51hKKD5sc3_9YA 密码: mn7r
下载 pytorch-cpu-0.3.1-py35_cpuhe774522_2.tar.bz2

conda install --offline pytorch-cpu-0.3.1-py35_cpuhe774522_2.tar.bz2
# 测试 tensorflow 和 pytorch是否正常工作
import tensorflow as tf  
import torch
from torch.backends import cudnn

hello = tf.constant('Hello, TensorFlow!')  
sess = tf.Session()  
print(sess.run(hello))

x = torch.Tensor([1, 3])
y = torch.Tensor([2, 4])
z = x + y
# z = z.cuda()    # cpu版本没有cuda  
print(z)
print(cudnn.is_acceptable(x))

你可能感兴趣的:(20,深度学习)