当前位置: 代码迷 >> 综合 >> UnboundLocalError local variable torch referenced before assignment
  详细解决方案

UnboundLocalError local variable torch referenced before assignment

热度:30   发布时间:2024-01-12 18:08:04.0

一开始 import torch,在 vscode 中,torch 显示灰色

这是因为在代码的某个地方又使用了 import torch, 去掉就OK了

在 stackoverflow 里看到的解释:----链接----- ,580多赞的那个回答

The Python interpreter sees this at module load time and decides (correctly so) that the global scope's Var1 should not be used inside the local scope, which leads to a problem when you try to reference the variable before it is locally assigned.

  相关解决方案