Pytorch环境搭建

太一吾鱼水 / 2023-08-29 / 原文

 https://pytorch.org/

 

https://blog.csdn.net/weixin_43737866/article/details/127784768

https://www.jianshu.com/p/4c7b9127cf83

https://blog.csdn.net/m0_56945481/article/details/126998629

第一次装Anaconda3最新版,报Solving environment: failed with initial frozen solve. Retrying with flexible solve.

搞了这个命令

conda config --add channels conda-forge
conda config --set channel_priority flexible

之后,更新conda,完了之后报错ImportError: DLL load failed while importing _ctypes: 找不到指定的模块。

1.于是重装Anaconda3-5.3.1-Windows-x86_64

(base) C:\Users\yhexie>conda info

CustomValidationError: Parameter channel_priority = 'flexible' declared in C:\Users\yhexie\.condarc is invalid.
The value 'flexible' cannot be boolified.

2.删除C:\Users\yhexie\.condarc,重新启动。

https://blog.csdn.net/xu96944967/article/details/127595899

3.conda安装的居然没有cuda支持,然后换一个虚拟环境继续装

pip install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio==0.10.1 --extra-index-url https://download.pytorch.org/whl/cu102

这个命令跑了2遍,成功了。

检查:

import torch

print(torch.__version__) #查看pytorch版本

print(torch.cuda.is_available()) #查看cuda是否可用 输出为True 或者False

 

(利用conda命令总是不成功,也可以尝试使用pip命令进行安装,这时就需要将镜像源改成pip的镜像源;同时如果conda命令和pip命令都不行,也可以利用先下载whl文件,然后pip直接安装的方法。)