V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
XIVN1987
V2EX  ›  Jupyter

jupyter-nbconvert.exe --generate-config 报错 UnicodeEncodeError: 'gbk'

  •  
  •   XIVN1987 · Dec 30, 2020 · 2480 views
    This topic created in 1951 days ago, the information mentioned may be changed or developed.

    报错信息为:

      File "c:\python36\venv\lib\site-packages\jupyter_core\application.py", line 156, in write_default_config
        f.write(config_text)
    UnicodeEncodeError: 'gbk' codec can't encode character '\xb6' in position 8440: illegal multibyte sequence
    

    查看“jupyter_core\application.py”内容如下:

    with open(config_file, mode='w') as f:
        f.write(config_text)
    

    改成:

    with open(config_file, mode='w', encoding='utf-8') as f:
        f.write(config_text)
    

    重新执行,执行成功,不再报错

    这是 bug 吗?我要去提个 issue 吗?

    2 replies    2020-12-30 22:40:55 +08:00
    ysc3839
        1
    ysc3839  
       Dec 30, 2020 via Android
    个人觉得不算 bug,而是考虑不周全,没有检测文件编码。
    个人建议加个命令行参数,让用户手动指定文件编码。
    Jirajine
        2
    Jirajine  
       Dec 30, 2020 via Android
    这是陈年老 bug(feature)了。Python 在 Windows 下默认使用系统环境的编码方式。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1080 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 23:58 · PVG 07:58 · LAX 16:58 · JFK 19:58
    ♥ Do have faith in what you're doing.