一开始 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.