windows 属性错误:模块“os”没有属性“geteuid”

9rygscc1  于 2023-04-13  发布在  Windows
关注(0)|答案(1)|浏览(933)

在Win 11上运行代码时

# 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.

所以我想知道如何在Win 11上将os.getuid()替换成其他的,或者如何获得"--dist-url”

pbpqsu0x

pbpqsu0x1#

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

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

我们可以在Windows上使用getpass.getuser()

相关问题