首页 > 解决方案 > 此命令 fig, axs = plt.subplots(2, 2) 显示错误 UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

问题描述

我在 spyder 中运行以下命令,

将 matplotlib.pyplot 导入为 plt

fig, axs = plt.subplots(2, 2) Traceback(最近一次通话最后):

文件“/home/hh/.local/lib/python3.8/site-packages/matplotlib_inline/backend_inline.py”,第 41 行,显示显示(

文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/IPython/core/display.py”,第 327 行,显示 publish_display_data(data=format_dict, metadata=md_dict, **kwargs )

文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/IPython/core/display.py”,第 119 行,在 publish_display_data display_pub.publish(

发布 self.session.send(

文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/jupyter_client/session.py”,第 830 行,在发送 to_send = self.serialize(msg, ident)

序列化内容 = self.pack(content) 中的文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/jupyter_client/session.py”,第 704 行

json_packer 中的文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/jupyter_client/session.py”,第 95 行,返回 jsonapi.dumps(

文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/zmq/utils/jsonapi.py”,第 40 行,转储 s = jsonmod.dumps(o, **kwargs)

转储中的文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/simplejson/init .py ”,第 398 行,返回 cls(

文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/simplejson/encoder.py”,第 296 行,编码块 = self.iterencode(o, _one_shot=True)

文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/simplejson/encoder.py”,第 378 行,在 iterencode 返回 _iterencode(o, 0)

文件“/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/simplejson/encoder.py”,第 44 行,位于 encode_basestring s = str(s, 'utf-8')

UnicodeDecodeError:“utf-8”编解码器无法解码位置 0 的字节 0x89:无效的起始字节

如果我在 jupyter lab 中运行相同的代码,则会出现相同的错误。但是,如果我在终端上运行命令,则 fig, ax = plt.subplots() 工作正常。

这只发生在最近,我之前没有遇到过这个问题。查了网上资料,没找到解决办法。如果只能提供任何见解,请不胜感激。谢谢。

标签: python-unicode

解决方案


我在运行普通的 jupyter 和 vscode 时遇到了同样的问题。尝试更新 jupyter 安装,包括。所需的库。就我而言

pip3 install --upgrade jupyter_client pyzmq

解决了这个问题。


推荐阅读