pythonwindowsdetectron

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


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"?


Solution

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