• TensorFlow与pytorch特定版本虚拟环境的安装


    TensorFlow与Python的版本对应,注意,一定要选择对应的版本,否则会让你非常痛苦,折腾很久搞不清楚原因。

    在这里插入图片描述
    建议使用国内镜像源安装
    没有GPU后缀的就表示是CPU版本的,不加版本就是最新

    pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 1

    还可以指定版本

    pip install tensorflow==1.8 -i https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 1

    GPU版本

    pip install tensorflow-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple
    pip install tensorflow-gpu==1.8 -i https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 1
    • 2

    完成虚拟环境配置以及包的安装就可以运行程序啦
    如下,成功了
    在这里插入图片描述
    pytorch也是一样,但是要注意去pytorch官网上进行版本的匹配和选择
    https://pytorch.org/get-started/previous-versions/
    在这里插入图片描述
    这里有不同模块的版本对应,一定要看清楚了再安装下载,不然很容易失败。torchvision是专门做视觉的,如果不需要可以不下
    在这里插入图片描述
    cuda和pytorch的对应
    在这里插入图片描述

    安装,用清华源加速

    pip install torch===1.7.0 torchvision===0.8.0 -i https://pypi.tuna
    .tsinghua.edu.cn/simple
    
    • 1
    • 2

    然后,出错了,ERROR: torch has an invalid wheel, .dist-info directory not found
    巧的是,貌似只有1.7安装会出现这个问题,这个时候就不要再使用清华源了,所以有时候国内镜像源并非全能。
    恢复到国外的

    pip install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
    
    • 1

    注意,以上语法均是临时使用清华源加速,若想默认,则使用以下语句设置

    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 1

    另外也可以使用离线下载安装

    https://download.pytorch.org/whl/torch_stable.html

    在这里插入图片描述
    选择需要的版本进行下载,cu102 # 表示 CUDA=10.2 ,cp37 # 表示 python=3.7

    下载好 torch 的 .whl 文件后,用 pip 安装,先 cd 到下载的文件夹,然后执行安装命令

    pip install torch-1.7.0+cu101-cp36-cp36m-win_amd64.whl
    
    • 1

    如果下载了torchvision,则安装也是一样

    pip install torchvision-0.8.0-cp36-cp36m-win_amd64.whl
    
    • 1

    注意注意注意

    报错一般情况下都是因为版本不匹配的问题,所以出错了一定要从版本入手检查问题,这样才更容易解决问题
    在这里插入图片描述

  • 相关阅读:
    API集成测试:SpringBoot+Junit
    【ACWing】3488. 最短路径
    分布式文件系统JuiceFS测试总结
    初学C语言有什么建议?
    MySQL面试题——隔离级别相关面试题
    Kotlin中for循环的补充
    对导航简单分析
    计算机毕业设计springboot+vue基本微信小程序的小区防疫监管系统
    base_network
    Session 和 Cookie 使用
  • 原文地址:https://blog.csdn.net/eyexin2018/article/details/132801324