1
votes

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()
1
This seems to be an issue with tkinter on macOs, but probably with some particular combination of tcl, tk and python. Here are two similar examples I found stackoverflow.com/questions/48085420/… and github.com/Qirky/FoxDot/issues/32. Not much help to you but maybe someone more knowledgeable about tkinter might have some ideas.snakecharmerb
@snakecharmerb thanks...at least I can try somethingZaki Zakaria

1 Answers

0
votes

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

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