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

成功!

相关推荐
石迹耿千秋6 小时前
迁移学习--基于torchvision中VGG16模型的实战
人工智能·pytorch·机器学习·迁移学习
qiqiqi(^_×)10 小时前
卡在“pycharm正在创建帮助程序目录”
ide·python·pycharm
Lum110413 小时前
PyCharm高效入门指南大纲
ide·python·pycharm
LGGGGGQ13 小时前
嵌入式学习-PyTorch(7)-day23
人工智能·pytorch·学习
甄卷13 小时前
李沐动手学深度学习Pytorch-v2笔记【08线性回归+基础优化算法】2
pytorch·深度学习·算法
PyAIExplorer13 小时前
PyTorch 损失函数详解:从理论到实践
人工智能·pytorch·python
霖0018 小时前
神经网络项目--基于FPGA的AI简易项目(1-9图片数字识别)
人工智能·pytorch·深度学习·神经网络·机器学习·fpga开发
Marst Code18 小时前
PyCharm(入门篇)
ide·python·pycharm
聚客AI18 小时前
💡大模型开发从入门到部署:3个月避开87%的新手雷区
人工智能·pytorch·llm
做科研的周师兄19 小时前
PyCharm 高效入门指南:从安装到进阶,解锁 Python 开发全流程
ide·python·pycharm