简体   繁体   English

python虚拟环境中plot.show()期间的UnicodeDecodeError

[英]UnicodeDecodeError during plot.show() in python virtual environment

Hi I'm currently trying to experiment with deep learning with python in my Mac terminal. 嗨,我目前正在Mac终端中尝试使用python进行深度学习。 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). 到目前为止,我所做的是创建一个虚拟环境并安装了所需的所有需求,例如Tensorflow,Keras和库(其中一个是与问题相关的matplotlib )。 My python version is 3.7 . 我的python版本是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() 追溯(最近一次通话最后一次):在plt.show()中的文件“ deepLearning.py”,第17行
File "/Users/zaki/venv/lib/python3.7/site-packages/matplotlib/pyplot.py", line 253, in show return _show(*args, **kw) 文件“ /Users/zaki/venv/lib/python3.7/site-packages/matplotlib/pyplot.py”,第253行,在show return _show(* args,** kw)中
File "/Users/zaki/venv/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 3266, in show cls.mainloop() 在显示cls.mainloop()中,文件“ /Users/zaki/venv/lib/python3.7/site-packages/matplotlib/backend_bases.py”,行3266
File "/Users/zaki/venv/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 1037, in mainloop Tk.mainloop() 文件“ /Users/zaki/venv/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py”,行1037,在主循环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) 文件“ /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/ init .py”,行557,位于主循环_default_root.tk.mainloop(n )

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte UnicodeDecodeError:“ utf-8”编解码器无法解码位置0的字节0xff:无效的起始字节

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: 当我设法解决时,调用plt.show()plt.show()相同的问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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