pycharm添加虚拟环境以及虚拟环境安装pytorch

  1. file、settings、interpreter、add interpreter、add local interpreter

    记住不要勾选inherit,不然会把主环境的东西继承到虚拟环境。

    创建前可以先点existing看看有没有已经建好的虚拟环境

  2. 有的时候pycharm有问题,创建了虚拟环境没有显示。找一个.py文件,上方会弹出提醒,选择使用interpreter,选择刚刚建好的虚拟环境。

  3. 记得重新打开terminal,如果前面有(venv),说明是在虚拟环境中。

  4. pytorch官网,pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

  5. 运行一段代码,调用gpu看看行不行

    import torch

    if torch.cuda.is_available():
    print("检测到当前设备有可用GPU:")
    print("当前可用GPU数量:", torch.cuda.device_count())
    print("当前GPU索引:", torch.cuda.current_device())
    print("当前GPU名称:", torch.cuda.get_device_name(torch.cuda.current_device()))
    else:
    print("未检测到当前设备有可用GPU,不建议开始训练,如有需求请自行更改代码:")
    exit()

成功!

相关推荐
AI即插即用8 小时前
即插即用系列 | 2025 MambaNeXt-YOLO 炸裂登场!YOLO 激吻 Mamba,打造实时检测新霸主
人工智能·pytorch·深度学习·yolo·目标检测·计算机视觉·视觉检测
忘却的旋律dw10 小时前
使用LLM模型的tokenizer报错AttributeError: ‘dict‘ object has no attribute ‘model_type‘
人工智能·pytorch·python
studytosky12 小时前
深度学习理论与实战:MNIST 手写数字分类实战
人工智能·pytorch·python·深度学习·机器学习·分类·matplotlib
小女孩真可爱1 天前
大模型学习记录(五)-------调用大模型API接口
pytorch·深度学习·学习
Predestination王瀞潞1 天前
Windows环境下Pytorch的配置
人工智能·pytorch·python
夫唯不争,故无尤也1 天前
PyTorch 的维度变形一站式入门
人工智能·pytorch·python
nix.gnehc1 天前
PyTorch
人工智能·pytorch·python
z樾1 天前
TorchRL-MADDPG
pytorch·python·深度学习
夫唯不争,故无尤也2 天前
梯度累计原理:数学可行性与PyTorch实现
人工智能·pytorch·python
G***T6912 天前
GitGraphQL案例
pycharm·perl·etl