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极简,不带pip
1、安装uv
pip install uv
2、创建虚拟环境
uv venv --python=python3.11
3、激活虚拟环境
.venv\Scripts\activate.bat
4、下载jupyter
pip install jupyter -i https://pypi.mirrors.ustc.edu.cn/simple/
5、打开jupyter
uv run jupyter lab
2)在pycharm中
新建项目New Project,在解释器类型选择项目venv创建虚拟环境
打开Terminal终端,路径前有(.venv)即表示虚拟环境已激活
2、安装pytorch
PyTorch官网,找到和自己cuda版本和驱动版本匹配的pytorch,
历史版本网页:Previous PyTorch Versions
在cmd中输入nvidia-smi可以查看CUDA版本和驱动版本
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117官网下载太慢
通过Ctrl+C终止下载,复制找到的下载地址,用迅雷下载
或者使用镜像文件下载
镜像文件下载地址:https://download.pytorch.org/whl/torch/
下载完成后,在终端输入以下语句,进行本地下载
pip install D:\DaiMa\PythonCode\Learning_Pytorch\torch-2.0.1+cu117-cp311-cp311-win_amd64.whl如果失败可能是因为,默认从清华源下载,改为使用以下语句即可
pip install D:\DaiMa\PythonCode\Learning_Pytorch\torch-2.0.1+cu117-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 torchvision==0.15.2 torchaudio==2.0.2由于默认在清华源下载,还是报错,改为
pip install torchvision==0.15.2 torchaudio==2.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 版本)查找这几个主包。torchvision==0.15.2和torchaudio==2.0.2通常是对应 CUDA 11.7 的版本组合。--extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple:将清华源设置为备用源。如果这些包还有其他依赖(比如numpy、pillow),pip 会从清华源下载,这样速度会更快
这样就下载成功啦!
4、安装matplotlib pandas
清华源还是没有,改用阿里云下载
pip install matplotlib pandas -i https://mirrors.aliyun.com/pypi/simple/5、查看
使用这个命令行,检查安装的包
pip list
安装完成!