ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

Pytorch安装教程

Pytorch安装教程 1、创建虚拟环境1在cmd中工作目录D:\DaiMa\PythonCode\LLMS\LLMs-from-scratch-main虚拟空间D:\DaiMa\PythonCode\LLMS\LLMs-from-scratch-main\.venv激活虚拟空间进入工作目录打开cmd输入 .venv\Scripts\activate.bat输入where python(where pip)显示使用的python和pip应来源于虚拟空间用uv包管理器创建环境的话的话pip不来自虚拟空间因为uv极简不带pip1、安装uvpip install uv2、创建虚拟环境uv venv --pythonpython3.113、激活虚拟环境.venv\Scripts\activate.bat4、下载jupyterpip install jupyter -i https://pypi.mirrors.ustc.edu.cn/simple/5、打开jupyteruv run jupyter lab2在pycharm中新建项目New Project在解释器类型选择项目venv创建虚拟环境打开Terminal终端路径前有.venv即表示虚拟环境已激活2、安装pytorchPyTorch官网找到和自己cuda版本和驱动版本匹配的pytorch历史版本网页Previous PyTorch Versions在cmd中输入nvidia-smi可以查看CUDA版本和驱动版本pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117官网下载太慢通过CtrlC终止下载复制找到的下载地址用迅雷下载或者使用镜像文件下载镜像文件下载地址https://download.pytorch.org/whl/torch/下载完成后在终端输入以下语句进行本地下载pip install D:\DaiMa\PythonCode\Learning_Pytorch\torch-2.0.1cu117-cp311-cp311-win_amd64.whl如果失败可能是因为默认从清华源下载改为使用以下语句即可pip install D:\DaiMa\PythonCode\Learning_Pytorch\torch-2.0.1cu117-cp311-cp311-win_amd64.whl -i https://pypi.org/simple这样就是下载成功了在控制台输入以下语句输出True证明GPU版的torch已经正常安装import torch torch.cuda.is_available()3、安装torchvision、torchaudio在 历史版本网页Previous PyTorch Versions 中找到与自己CUDA版本相匹配的历史版本复制该命令把torch删掉已经下载过了pip install torchvision0.15.2 torchaudio2.0.2由于默认在清华源下载还是报错改为pip install torchvision0.15.2 torchaudio2.0.2 --index-url https://download.pytorch.org/whl/cu117 --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple其含义是--index-url https://download.pytorch.org/whl/cu117告诉 pip 优先从 PyTorch 官方源CUDA 11.7 版本查找这几个主包。torchvision0.15.2和torchaudio2.0.2通常是对应 CUDA 11.7 的版本组合。--extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple将清华源设置为备用源。如果这些包还有其他依赖比如numpy、pillowpip 会从清华源下载这样速度会更快这样就下载成功啦4、安装matplotlib pandas清华源还是没有改用阿里云下载pip install matplotlib pandas -i https://mirrors.aliyun.com/pypi/simple/5、查看使用这个命令行检查安装的包pip list安装完成
返回列表