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

成功!

相关推荐
风合星语2 天前
2026 具身智能技术实战(一):VLA 到底怎么控制机器人?——用 LeRobot 跑通 SmolVLA 推理
pytorch·机器人·具身智能·vla·lerobot·smolvla
Tancenter2 天前
sequeeze()和unsequeeze()
pytorch·tensorr
Thomas.Sir2 天前
第21课:PyTorch|GPU多卡训练与分布式训练基础【让多卡并行成为你的加速引擎】
人工智能·pytorch·分布式
慧都小项2 天前
Python 跨文件重构怎么验证?PyCharm 用法查找、重构预览与测试流程
python·重构·pycharm·单元测试
CODER03042 天前
ubuntu22.04部署完整deepseek局域网web服务全过程(RTX5090安装黑屏+web端多人并发)
pytorch·webui·ubuntu22.04·ollama·deepseek·rtx5090·自然语言模型
Xiu Yan2 天前
Python 数据分析:Pandas DataFrame 零基础入门教程
python·jupyter·pycharm·numpy·pandas
ai大模型-探索者2 天前
Git在PyCharm中的使用完全指南
pycharm·gitee
宿州派大星2 天前
[NLP实战] 基于PyTorch实现N-gram词嵌入模型:输入4个词预测第5个词
人工智能·pytorch·深度学习·nlp
Liaiyang663 天前
空圈容错视角下的无人机全链路审计:从理论框架到耦合式检验
人工智能·pytorch·python·深度学习·系统架构·自动驾驶·无人机
AI模力圈3 天前
Pytorch图模式技术原理解析
pytorch·深度学习·torch.compile