pycharm中os.environ不能读取环境变量CUDA_VISIBLE_DEVICES,显示raise KeyError(key) from None

问题描述:os.environ[环境变量名],但os.environ不能读取环境变量CUDA_VISIBLE_DEVICES

解决措施:1.如下图Run--->Edit Configurations

2.如下图添加CUDA_VISIBLE_DEVICES环境变量

 

大功告成!

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
os.environ["cuda_visible_devices"]是一个环境变量,用于限制程序所能看到的可用GPU设备列表,从而确保程序只使用指定的GPU设备。可以通过设置os.environ["cuda_visible_devices"]来指定程序能够看到的GPU设备。比如,使用os.environ["cuda_visible_devices"] = '0,1',可以让程序只看到编号为0和1的GPU设备。这样可以确保程序只在指定的GPU设备上运行。 这个环境变量的设置可以通过两种方式进行:一种是使用import os模块,然后通过os.environ['cuda_visible_devices'] = '0,1'这样的语句进行设置;另一种是使用import torch模块,然后通过torch.cuda.set_device(0)这样的语句进行设置。 通过设置os.environ['cuda_visible_devices']环境变量,可以灵活地控制程序在多个GPU设备上运行的行为。这样的设置对于需要使用多个GPU设备并具有特定需求的程序非常有用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [os.environ[‘CUDA_VISIBLE_DEVICES‘] 和torch.cuda.set_device()](https://blog.csdn.net/weixin_46141646/article/details/129052145)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [Python基于os.environ从windows获取环境变量](https://download.csdn.net/download/weixin_38698149/12851183)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

什么都小白6

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值