Win10+Anaconda+Pytorch_CPU+VsCode安装配置

一、安装Anaconda

1,官网下载Anaconda安装包,找到对应版本的python,我下的是Anaconda3-2020.07-Windows-x86_64.exe,python版本为3.8.3;
安装时注意这个界面时
在这里插入图片描述
第一个不要勾选,安装成功后,手动配置;
找到安装路径下的这几个文件夹,将其添加到系统变量中
E:\Anaconda
E:\Anaconda\Scripts
E:\Anaconda\Library\mingw-w64\bin
E:\Anaconda\Library\usr\bin
E:\Anaconda\Library\bin
在这里插入图片描述
其他的默认即可;

二、安装VsCoda

在官网下载默认安装;

三、安装Pytorch

打开Anaconda powershell Prompt
输入命令: conda create -n pytorch python=3.8
其中pytorch是虚拟环境的名字,3.8是python的版本。
输入命令: conda activate pytorch
激活pytorch虚拟环境;

检测自己的电脑是否存在Navida的显卡,然后进入官网链接: https://pytorch.org/
官网为最新的2.0版本
在这里插入图片描述
复制方框中的语句到powershell中,回车安装,若安装包下载失败,这重新打开powershell重新安装;

也可以选择历史版本:https://pytorch.org/get-started/previous-versions/
在虚拟环境中,输入命令python
接着输入命令import torch
接着输入命令torch.cuda.is_available()
在这里插入图片描述
安装成功;

四、在VsCode中配置pytorch

vscode中配置json,打开Vscode,左上角点击文件>>首选项>>设置>>扩展,在扩展中找到python,点击右侧:
在这里插入图片描述
设置自己的路径找到自己的虚拟环境的python.exe的路径:
在这里插入图片描述
重启VsCode,新建.py文件输入:

import torch
print(torch.cuda.is_available())

运行成功则设置成功;

五、报错

VSCode terminal powershell 激活创建好的虚拟环境出现错误:

报错:CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘.

解决步骤
1、在VSCode terminal powershell 中执行

conda init

后重启vscode,忽略错误信息进行下一步;
2、Windows10 全局搜关键字powershell 以管理员权限打开,输入命令

set-ExecutionPolicy RemoteSigned

然后再输入‘Y’,之后回车确定执行命令就行;
3、再重启一下VSCode terminal powershell 输入命令 conda activate [虚拟环境名称],就能发现终于正确切换conda 虚拟环境了;

参考链接:

https://blog.csdn.net/fan18317517352/article/details/123035625
https://blog.csdn.net/weixin_45769992/article/details/125862617
https://blog.csdn.net/qq_44921056/article/details/128068538
https://blog.csdn.net/weixin_64064486/article/details/123972443

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值