Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

[resolved] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte #13

Open
program-spiritual opened this issue Mar 15, 2019 · 3 comments

Comments

@program-spiritual
Copy link
Owner

显示图像是空白,鼠标在上面滚动一下 就会报错

image

报错日志如下:

环境: pipenv pyenv

错误日志

Traceback (most recent call last):
  File "demo4.py", line 103, in <module>
    create_word_cloud(all_word)
  File "demo4.py", line 66, in create_word_cloud
    plt.show()
  File "/Users/huhongyun/PythonProjects/geekTimeDataAnalysisInAction/.venv/lib/python3.6/site-packages/matplotlib/pyplot.py", line 254, in show
    return _show(*args, **kw)
  File "/Users/huhongyun/PythonProjects/geekTimeDataAnalysisInAction/.venv/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 3266, in show
    cls.mainloop()
  File "/Users/huhongyun/PythonProjects/geekTimeDataAnalysisInAction/.venv/lib/python3.6/site-packages/matplotlib/backends/_backend_tk.py", line 1039, in mainloop
    managers[0].window.mainloop()
  File "/Users/huhongyun/.pyenv/versions/3.6.7/lib/python3.6/tkinter/__init__.py", line 1283, in mainloop
    self.tk.mainloop(n)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
@program-spiritual
Copy link
Owner Author

为了兼容 pyenv 环境下的代码兼容性问题:

我添加了如下代码

import matplotlib

matplotlib.use('TkAgg')

@program-spiritual program-spiritual changed the title 第38讲 demo4.py: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte [resolved] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte Mar 16, 2019
@program-spiritual
Copy link
Owner Author

解决方案 :(替换渲染引擎)

  1. 安装PyQt5

pip3 install PyQt5

  1. 设置 backend backend: Qt4Agg
echo "backend: Qt4Agg" >> ~/.matplotlib/matplotlibrc

或者

vim    ~/.matplotlib/matplotlibrc

添加:

backend: Qt4Agg

@program-spiritual
Copy link
Owner Author

新的渲染图:

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant