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

成功!

相关推荐
BBB努力学习程序设计9 小时前
Python异步编程完全指南:从asyncio到高性能应用
python·pycharm
BBB努力学习程序设计9 小时前
Python迭代器与生成器深度解析:懒加载的艺术
python·pycharm
BigerBang10 小时前
LoRA 全方位指南:从底层原理到 Qwen-Image-Edit 实战
人工智能·pytorch·深度学习·算法
攻城狮之路人甲11 小时前
用pycharm写的程序,点击.py无法运行闪退
ide·python·pycharm
Aevget12 小时前
Python开发利器PyCharm v2025.3全新发布——支持主动数据探索
开发语言·ide·python·pycharm
子夜江寒12 小时前
PyTorch:基于MNIST的手写数字识别
pytorch·python·深度学习
island131412 小时前
PyTorch 2.0 核心技术深度解析torch.compile 从原理到实践
人工智能·pytorch·python
_爱明13 小时前
查看模型参数量
人工智能·pytorch·python
幽影相随14 小时前
TensorBoard 快速使用指南
pytorch·python·tensorboard
其美杰布-富贵-李14 小时前
TensorBoard 与 WandB 在 PyTorch Lightning 中的完整指南
人工智能·pytorch·python·监控·调优