Python:运行散景服务时在Windows上编码的麻烦(散景图库)

时间:2017-09-13 01:33:05

标签: bokeh

当我运行

时,我正在使用Bokeh创建交互式图

boken serve myapp.py

我得到了

'gbk' codec can't decode byte 0xad in position 2196: illegal multibyte sequencencoding

我知道这与编解码器问题有关,因为我一直在那里使用中文字符。有a similar discussion in stackoverflow 。但是在这里我无法使用output_file来设置编码,因为在我的情况下需要curdoc。我如何解决这个问题?我正在使用具有中文字符支持的Window机器,尝试过chcp 65001,它也不起作用。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。希望这会有所帮助。

问题出在site-packages\bokeh\application\handlers\script.py第53行。我认为这使用了Windows的默认编解码器(例如'gbk')。

如果您确保myapp.py已保存在utf8-without-bom中,请将此行更改为:

with open(filename, 'r', encoding='utf8') as f:

它应该有用。

相关问题