属性错误:模块'os'没有属性'geteuid'



当我在Win11上运行代码

# PyTorch still may leave orphan processes in multi-gpu training.
# Therefore we use a deterministic way to obtain port,
# so that users are aware of orphan processes by seeing the port occupied.

port = 2 ** 15 + 2 ** 14 + hash(os.getuid()) % 2 ** 14
parser.add_argument(
"--dist-url", default="tcp://127.0.0.1:{}".format(port)
)

它引发错误,如

AttributeError: module 'os' has no attribute 'geteuid'

我在github上找到了一个像这样的答案

geteuid() is only available on unix like systems. This explains why it doesn't work on Windows.
所以我想知道如何替换os.getuid()或者我怎么能得到"——dist-url">?

我已经在win11上解决了这个问题

if os.name=='nt':
port = 2 ** 15 + 2 ** 14 + hash(getpass.getuser()) % 2 ** 14

可以使用getpass.getuser()在Windows .

最新更新