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

成功!

相关推荐
应用市场1 小时前
Adam优化器深度解析:从数学原理到PyTorch源码实
人工智能·pytorch·python
70asunflower5 小时前
torch.manual_seed()介绍
人工智能·pytorch·python
【赫兹威客】浩哥9 小时前
【赫兹威客】Pycharm安装详细教程
python·pycharm
sunfove10 小时前
拥抱不确定性:使用 PyTorch 构建贝叶斯神经网络 (BNN)
人工智能·pytorch·神经网络
bst@微胖子20 小时前
LlamaIndex之核心概念及部署以及入门案例
pytorch·深度学习·机器学习
停走的风1 天前
anaconda与pycharm卸载重安装笔记
笔记·pycharm·conda
C系语言1 天前
Anaconda虚拟环境,完全使用conda install命令安装所有包,使用conda install pytorch
人工智能·pytorch·conda
TangKenny1 天前
jar 命令详解
java·pycharm·jar
wuxin_91022 天前
Android Studio打Jar包
pycharm·android studio·jar
不如语冰2 天前
AI大模型入门1.1-python基础-数据结构
数据结构·人工智能·pytorch·python·cnn