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()

成功!

相关推荐
All The Way North-3 小时前
PyTorch从零实现CIFAR-10图像分类:保姆级教程,涵盖数据加载、模型搭建、训练与预测全流程
pytorch·深度学习·cnn·图像分类·实战项目·cifar-10·gpu加速
没学上了6 小时前
VLM-单头自注意力机制核心逻辑
人工智能·pytorch·深度学习
实战项目6 小时前
基于PyTorch的卷积神经网络花卉识别系统
人工智能·pytorch·cnn
没学上了8 小时前
SLM-多头注意力机制
pytorch·python·深度学习
GZKPeng8 小时前
pytorch +cuda成功安装后, torch.cuda.is_available 是False
人工智能·pytorch·python
二哈喇子!1 天前
PyTorch生态与昇腾平台适配:环境搭建与详细安装指南
人工智能·pytorch·python
UnderTurrets1 天前
A_Survey_on_3D_object_Affordance
pytorch·深度学习·计算机视觉·3d
koo3641 天前
pytorch深度学习笔记13
pytorch·笔记·深度学习
山土成旧客1 天前
【Python学习打卡-Day40】从“能跑就行”到“工程标准”:PyTorch训练与测试的规范化写法
pytorch·python·学习
缘友一世1 天前
PyCharm连接autodl平台服务(python解释器&jupyter lab)
python·jupyter·pycharm