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'
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.
Thanks for your error report and we appreciate it a lot.
Checklist
Describe the bug
I used a PyCharm. When collecting env info, the error happened about the codec.
Reproduction
Environment
PyCharm
Error traceback
Bug fix
The problem is here: In mmcv/utils/env.py
The
os.device_encoding()
in document():So when I run the code in PyCharm, it will get an error.