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

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

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

问题

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

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

I have found an answer on GitHub like this:

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

  1. # PyTorch still may leave orphan processes in multi-gpu training.
  2. # Therefore we use a deterministic way to obtain port,
  3. # so that users are aware of orphan processes by seeing the port occupied.
  4. port = 2 ** 15 + 2 ** 14 + hash(os.getuid()) % 2 ** 14
  5. parser.add_argument(
  6. "--dist-url", default="tcp://127.0.0.1:{}".format(port)
  7. )

it raise error as follow

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

I have found an answer on github like this

  1. 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上的这个问题。

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

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

英文:

I have solve this problems on win11

  1. if os.name=='nt':
  2. 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:

确定