open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.09k stars 9.38k forks source link

Function to find the "cl.exe" have a bug without a terminal #10546

Open novalli1993 opened 1 year ago

novalli1993 commented 1 year ago

Thanks for your error report and we appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. I have read the FAQ documentation but cannot get the expected help.
  3. The bug has not been fixed in the latest version.

Describe the bug

I used a PyCharm. When collecting env info, the error happened about the codec.

Reproduction

Environment

PyCharm

Error traceback

File "M:\XXXXX\train.py", line XXX, in main

env_info_dict = collect_env()

File "D:\anaconda3\envs\internimage\lib\site-packages\mmseg\utils\collect_env.py", line 10, in collect_env

env_info = collect_base_env()

File "D:\anaconda3\envs\internimage\lib\site-packages\mmcv\utils\env.py", line 91, in collect_env

env_info['MSVC'] = cc.decode(encoding).partition('\n')[0].strip()

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 in position 0: invalid continuation byte

Bug fix

The problem is here: In mmcv/utils/env.py

            # on Windows, cl.exe is not in PATH. We need to find the path.

            # distutils.ccompiler.new_compiler() returns a msvccompiler

            # object and after initialization, path to cl.exe is found.

            import os

            from distutils.ccompiler import new_compiler

            ccompiler = new_compiler()

            ccompiler.initialize()

            cc = subprocess.check_output(

                f'{ccompiler.cc}', stderr=subprocess.STDOUT, shell=True)

            encoding = os.device_encoding(sys.stdout.fileno()) or 'utf-8'

            env_info['MSVC'] = cc.decode(encoding).partition('\n')[0].strip()

            env_info['GCC'] = 'n/a'

The os.device_encoding() in document():

os.device_encoding() method in Python is used to get the encoding of the device associated with the specified file descriptor, if it is connected to a terminal. This method returns None, if the specified file descriptor is not connected to a terminal.

So when I run the code in PyCharm, it will get an error.

sdurmustalipoglu commented 2 months ago

I have the same problem. Did you solve it?