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

成功!

相关推荐
一瞬祈望4 小时前
ImportError: cannot import name ‘OrderedDict‘ from ‘typing‘ 问题解决
pytorch·python3.7
拾贰_C10 小时前
[Python | pytorch | torchvision ] models like ResNet... 命名变量说明
开发语言·pytorch·python
m0_4626052211 小时前
第N9周:seq2seq翻译实战-Pytorch复现-小白版
人工智能·pytorch·python
拾贰_C13 小时前
【Anaconda | Python | pytorch】sklearn scikit-learn 报错:
pytorch·python·sklearn
Mr.Lee jack14 小时前
【torch.compile】PyTorch Dynamo 和 Inductor 编译流程
人工智能·pytorch·深度学习
小张帅三代14 小时前
华为昇腾服务器ubuntu Anaconda安装PyTorch npu 版本 步骤
服务器·pytorch·ubuntu
撬动未来的支点14 小时前
【AI邪修·神经网络】神经网络基础—代码分析—手写数字识别
pytorch
idkmn_14 小时前
Daily AI 20251219 (PyTorch基础回顾3)
人工智能·pytorch·python·深度学习·神经网络
RwwH15 小时前
PyCharm虚拟环境创建
ide·python·pycharm
baby_hua15 小时前
20251011_Pytorch深度学习(快速预览)
人工智能·pytorch·深度学习