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

huangapple go评论52阅读模式
英文:

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

问题

When I run the code on Win11, it raises an error as follows:

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

I have found an answer on GitHub like this:

geteuid() is only available on Unix-like systems. This explains why it doesn't work on Windows.

So I want to know how to replace the os.getuid() with others on Win11 or how can I get the --dist-url?

英文:

when I run the code on 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)
    )

it raise error as follow

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

I have found an answer on github like this

geteuid() is only available on unix like systems. This explains why it doesn't work on Windows.

so I want to konw how to replace the os.getuid() with others on Win11,or how can I get the "--dist-url"?

答案1

得分: 0

我已解决了Win11上的这个问题。

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

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

英文:

I have solve this problems on win11

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

we can use getpass.getuser() on Windows.

huangapple
  • 本文由 发表于 2023年4月10日 20:42:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977215.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定