I am using Visual Studio Code, the encoding was set to UTF-16 LE. You can check the encoding on the right bottom side of VSCode. Just click on the encoding and select “save with encoding” and select UTF-8. It worked perfectly.
上面提到的vscode的解决方案,其实pycharm也有相同的功能。
用pycharm打开目标文件可以看到左下角的编码显示UTF-16F,
仔细观察可以发现其他所有python文件的编码都是UTF-8
点击UTF-16LE 在弹出的窗口中点击UTF-8,然后再弹出的对话框中选择Convert
问题解决
推测是文件编码不一致导致的问题