windows安装配置pytorch+vscode环境(纯入门轻喷)

学习路径

环境

配置目标

  1. 为机器学习项目服务-项目需要pytorch库
  2. 适应自己的编程习惯-惯用vscode,我已经安装了python插件

环境需求递归

  1. github项目:ConvLSTM_pytorch->需要pytorch库
  2. pyTorch环境->需要cuda(有GPU情况下)&conda
  3. CUDA(无需手动安装)
    1. GPU为外接1060 3G(穷)

    2. 电脑上安装的是Py3.10(实际上不需要,后面会在虚拟环境中重新安装)

    3. 所以应该选择pytorch-1.12.1-py3.10-cuda11.6的版本 (此处版本考虑并不必要,因为虚拟环境配置时会自动安装)故应选择cuda11.6.2使用

    4. 但anatorch会自动配置cuda环境调用显卡,故不用手动安装。

    5. 所以首先安装conda(anaconda),然后安装PyTorch环境,最后配置。

软件安装

  1. conda-anaconda-软件包/环境管理器
    1. Anaconda官网下载安装
    2. 开始菜单打开Anaconda Prompt
    3. 建立环境
    conda create -n pytorch_env python=3.10     (自己的python版本(并不需要和已经安装的版本相同))
    
    1. 更换下载源:csdn-conda下载换源
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
    conda config --set show_channel_urls yes
    
    1. 进入环境
    conda activate pytorch_env
    
  2. PyTorch环境配置及安装
    1. 从官网找到合适的Pytorch版本并复制指令:pytorch官网

    2. 在刚刚建立好的pytorch_env环境下使用指令

    3. 弹出详情列表,按Y回车安装

调试与配置:

  1. 命令行下:

    成功

  2. vscode下:
    在这里插入图片描述
    运行失败

文件-首选项-设置-扩展-Python-在settings.json中编辑
在settings.json文件中修改如下:

"python.defaultInterpreterPath": "C:\\Users\\amazc\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",

改为:

"python.defaultInterpreterPath": "C:\\Users\\amazc\\anaconda3\\envs\\pytorch_env\\python.exe",

即pytorch环境下python解释器
此时右下角弹出vscode的python拓展,提示更换解释器路径,更换即可。
在最后输入

"code-runner.executorMap":

这一句后会出现一大串提示,点第一个一样的后就会导入一大块语句
找到 “python”: “python -u” 这块,将其修改为对应的pytorch环境下python解释器路径即可。
最后是所有修改:

    //以下是安装pytorch时修改的
    "code-runner.executorMap":{
        "javascript": "node",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "php": "php",
        "python": "C:\\Users\\amazc\\anaconda3\\python.exe",
        "perl": "perl",
        "perl6": "perl6",
        "ruby": "ruby",
        "go": "go run",
        "lua": "lua",
        "groovy": "groovy",
        "powershell": "powershell -ExecutionPolicy ByPass -File",
        "bat": "cmd /c",
        "shellscript": "bash",
        "fsharp": "fsi",
        "csharp": "scriptcs",
        "vbscript": "cscript //Nologo",
        "typescript": "ts-node",
        "coffeescript": "coffee",
        "scala": "scala",
        "swift": "swift",
        "julia": "julia",
        "crystal": "crystal",
        "ocaml": "ocaml",
        "r": "Rscript",
        "applescript": "osascript",
        "clojure": "lein exec",
        "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
        "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
        "racket": "racket",
        "scheme": "csi -script",
        "ahk": "autohotkey",
        "autoit": "autoit3",
        "dart": "dart",
        "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
        "haskell": "runhaskell",
        "nim": "nim compile --verbosity:0 --hints:off --run",
        "lisp": "sbcl --script",
        "kit": "kitc --run",
        "v": "v run",
        "sass": "sass --style expanded",
        "scss": "scss --style expanded",
        "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
        "FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "sml": "cd $dir && sml $fileName"
    },
    "python.defaultInterpreterPath":"C:\\Users\\amazc\\anaconda3\\python.exe",
    //以上是安装pytorch时修改的

测试可以使用,但出现此情况:

将anaconda软件加入系统环境变量:

成功

  • 10
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装PyTorchVSCode是两个独立的过程。首先,你需要安装PyTorch。根据引用\[1\],你可以在PyTorch官方网站上找到安装指南。根据你的需求,你可以选择安装带有CUDA的版本(如果你有独立显卡)或者仅使用CPU版本。请确保按照官方指南进行安装,以确保兼容性和正确性。 安装VSCode是另一个过程。你可以从VSCode官方网站下载并安装VSCode安装过程非常简单,只需按照指示进行操作即可。 请注意,安装PyTorchVSCode时可能会遇到一些问题。根据引用\[3\],有时可能会出现一些依赖项无法安装的问题。如果你遇到这种情况,建议查看相关错误信息并尝试解决。此外,根据引用\[2\],如果你需要在不同的Python环境中使用不同的库,可以考虑使用虚拟环境来隔离它们,以避免环境混乱。 总结起来,安装PyTorchVSCode是两个独立的过程。你可以先按照官方指南安装PyTorch,然后从VSCode官方网站下载并安装VSCode。如果遇到问题,请查看相关错误信息并尝试解决。 #### 引用[.reference_title] - *1* *2* *3* [VScode+Anaconda+Pytorch环境搭建指南(超详细)](https://blog.csdn.net/weixin_43762840/article/details/121721264)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值