Couldn't Reload, what's wrong

[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) - Traceback (most recent call last):
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -   File "/Applications/Slice98.app/Contents/bin/Python/slicer/ScriptedLoadableModule.py", line 195, in onReload
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -     slicer.util.reloadScriptedModule(self.moduleName)
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -   File "/Applications/Slice98.app/Contents/bin/Python/slicer/util.py", line 1164, in reloadScriptedModule
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -     moduleName, fp, filePath, ('.py', 'r', imp.PY_SOURCE))
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -   File "/Applications/Slice98.app/Contents/lib/Python/lib/python3.6/imp.py", line 235, in load_module
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -     return load_source(name, filename, file)
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -   File "/Applications/Slice98.app/Contents/lib/Python/lib/python3.6/imp.py", line 170, in load_source
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -     module = _exec(spec, sys.modules[name])
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -   File "<frozen importlib._bootstrap>", line 618, in _exec
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -   File "<frozen importlib._bootstrap_external>", line 674, in exec_module
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -   File "<frozen importlib._bootstrap_external>", line 780, in get_code
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -   File "/Applications/Slice98.app/Contents/lib/Python/lib/python3.6/imp.py", line 156, in get_data
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -     return file.read()
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -   File "/Applications/Slice98.app/Contents/bin/../lib/Python/lib/python3.6/encodings/ascii.py", line 26, in decode
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) -     return codecs.ascii_decode(input, self.errors)[0]
[CRITICAL][Stream] 28.09.2021 18:24:37 [] (unknown:0) - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1034: ordinal not in range(128)

You used non-ASCII characters (probably international characters using UTF-8 encoding) in your source file.

Instead of writing unicode characters in your .py file, it is better if you write all the code and user-displayable text in English, using ASCII characters, and use translation infrastructure to replace it with text in any language, using UTF-8 encoding. Unfortunately, the translation infrastructure is not yet fully in place, but we have received funding recently and there should be significant progress in the coming months. See more information here.

In the short term, you can try if adding # coding: utf8 as the first line of your .py file fixes the issue. If that does not work, then you may need to replace utf-8 character by escape sequences. For example, instead of writing résumé, you can write b"r\xc3\xa9sum\xc3\xa9".decode("utf-8")

>>> "résumé".encode("utf-8")
b'r\xc3\xa9sum\xc3\xa9'

>>> b"r\xc3\xa9sum\xc3\xa9".decode("utf-8")
'résumé'

我用了Native-ASCII Converter - Visual Studio Marketplace

谢谢老师

On Windows and Linux module reload worked well with files using UTF-8 encoding, but apparently macOS had trouble. I’ve added explicit specification of the encoding, so you reloading will work if you use special characters in the file from tomorrow. That said, I would still highly recommend to keep the source code ASCII and use translation infrastructure to add messages in different languages.