Repository: open-mmlab/mmcv

Issue:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 in position 0: invalid continuation byte
在windows11上面，我使用`pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.11.0/index.html`安装了`mmcv-full 1.5.0`。
之后使用[测试脚本](https://github.com/open-mmlab/mmcv/blob/master/.dev_scripts/check_installation.py)测试是否安装成功，出现了如下错误:
```bash
C:\Users\ZhangQu\.conda\envs\mmlab\python.exe D:/masterResearch/envtest/check_mmcv.py
Start checking the installation of mmcv-full ...
CPU ops were compiled successfully.
CUDA ops were compiled successfully.
mmcv-full has been installed successfully.

Traceback (most recent call last):
  File "D:\masterResearch\envtest\check_mmcv.py", line 40, in <module>
    env_info_dict = collect_env()
  File "C:\Users\ZhangQu\.conda\envs\mmlab\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

Process finished with exit code 1
```


Discussion:
感谢你的反馈，这是 collect_env 中的一个编码问题，我们会尽快修复。另外，安装应该是没问题的，可正常使用
好的，谢谢


| |
张取
|
|
***@***.***
|
On 4/22/2022 10:17，Zaida ***@***.***> wrote：

感谢你的反馈，这是 collect_env 中的一个编码问题，我们会尽快修复。另外，安装应该是没问题的，可正常使用

—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
@creater-zq 请帮忙一下执行下面的命令，这将帮助我们定位问题：

```
import sys, os, locale
locale.getdefaultlocale()
sys.stdout.fileno()
os.device_encoding(sys.stdout.fileno())
```
> @creater-zq 请帮忙一下执行下面的命令，这将帮助我们定位问题：
> 
> ```
> import sys, os, locale
> locale.getdefaultlocale()
> sys.stdout.fileno()
> os.device_encoding(sys.stdout.fileno())
> ```

我在pycharm里面和anaconda的终端执行结果不一样？
![image](https://user-images.githubusercontent.com/59300179/164605111-f7ffff55-c061-4815-826e-2d5a9ad89069.png)

```
sys.getdefaultencoding()
```
@SuTanTank 
> ```
> sys.getdefaultencoding()
> ```
我是windows下测试的：
![image](https://user-images.githubusercontent.com/59300179/164616718-fd128368-aed4-4fbd-b900-78d5f760743b.png)


@SuTanTank 
 
```
import sys, os, locale

print(locale.getdefaultlocale())
print(sys.stdout.fileno())
print(os.device_encoding(sys.stdout.fileno()))
print(sys.getdefaultencoding())
 ```
* 我在Ubuntu20.04测试结果：
```bash
('zh_CN', 'UTF-8')
1
UTF-8
utf-8
```


Resolving patch:
diff --git a/mmcv/utils/env.py b/mmcv/utils/env.py
--- a/mmcv/utils/env.py
+++ b/mmcv/utils/env.py
@@ -81,13 +81,15 @@ def collect_env():
             # 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 locale
             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'
+            encoding = os.device_encoding(
+                sys.stdout.fileno()) or locale.getpreferredencoding()
             env_info['MSVC'] = cc.decode(encoding).partition('\n')[0].strip()
             env_info['GCC'] = 'n/a'
     except subprocess.CalledProcessError:


Test patch: