program-spiritual / DataAnalysisInAction

(Finished) Geek Time Data Analysis Practical 45 Lecture - Detailed notes containing markdown images mind map code data can be read directly code test
Other
702 stars 275 forks source link

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

Open program-spiritual opened 5 years ago

program-spiritual commented 5 years ago

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

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 commented 5 years ago

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

我添加了如下代码

import matplotlib

matplotlib.use('TkAgg')
program-spiritual commented 5 years ago

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

  1. 安装PyQt5

pip3 install PyQt5

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

    或者

    vim    ~/.matplotlib/matplotlibrc

    添加:

    backend: Qt4Agg
program-spiritual commented 5 years ago

新的渲染图:

image