python-unicode - 此命令 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() 工作正常。
这只发生在最近,我之前没有遇到过这个问题。查了网上资料,没找到解决办法。如果只能提供任何见解,请不胜感激。谢谢。
解决方案
我在运行普通的 jupyter 和 vscode 时遇到了同样的问题。尝试更新 jupyter 安装,包括。所需的库。就我而言
pip3 install --upgrade jupyter_client pyzmq
解决了这个问题。
推荐阅读
- java - 如何将 S3object 转换为 Observable
- codeigniter - 会话在 codeigniter 中不起作用
- mysql - 带有 3 个表的 SQL 请求
- php - Wordpress:PHP按随机性排序项目
- ios - Apple Wallet 支持 NFC 的通行证用例
- saucelabs - 宁静与 TestObject
- java - Swagger on a eclipse microprofile application
- avaudioplayer - AVAudioPlayer.duration 不等于 AVURLAsset.duration
- node.js - 在两个 docker 容器之间使用 HTTP 通信(Vue.js 到 Node.js)
- python - 如何根据时间是否在范围内创建由 1 或 0 填充的数组/数据框?