简体   繁体   中英

UnicodeDecodeError during plot.show() in python virtual environment

Hi I'm currently trying to experiment with deep learning with python in my Mac terminal. So far, what I did was create a virtual environment and installed all the requirements needed such as Tensorflow, Keras and the libraries (one of them is matplotlib which is related to the problem). My python version is 3.7 .

So when I try to execute my code below, I got this following error :

Traceback (most recent call last): File "deepLearning.py", line 17, in plt.show()
File "/Users/zaki/venv/lib/python3.7/site-packages/matplotlib/pyplot.py", line 253, in show return _show(*args, **kw)
File "/Users/zaki/venv/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 3266, in show cls.mainloop()
File "/Users/zaki/venv/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 1037, in mainloop Tk.mainloop()
File"/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/ init .py", line 557, in mainloop _default_root.tk.mainloop(n)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

from __future__ import print_function
from matplotlib import pyplot as plt

import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import RMSprop #pillow, from PIL import image, Opencv

batch_size = 128
num_classes = 10 # 0,1,2,3...10
epochs = 20

(x_train, y_train), (x_test,y_test) = mnist.load_data()

plt.imshow(x_train[1]) # this is to show the image
plt.show()

I have the same issue when calling plt.show() I managed to workaround with:

while True:
  try:
    plt.show()
    break
  except UnicodeDecodeError:
    continue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM