Этот код хорошо работает с Python 2.7.17 (python test.py
), но выдает кучу сообщений об ошибках с Python 3.6.9 (python3 test.py
).
Что не так с code?
Я видел несколько похожих вопросов, включая UnicodeDecodeError
, но не могу это исправить.
Я нахожусь на рабочем столе Ubuntu 18.04.3.
Мой код:
import cv2
import matplotlib.pyplot as plt
import matplotlib.animation as animation
imgarr = []
imgarr.append(cv2.imread('../../img/circle-1.png', cv2.IMREAD_GRAYSCALE))
imgarr.append(cv2.imread('../../img/circle-2.png', cv2.IMREAD_GRAYSCALE))
fig = plt.figure("ArtistAnimation")
img = []
for i in range(2):
img.append([plt.imshow(imgarr[i], cmap='gray')])
ani = animation.ArtistAnimation(fig,
img,
interval=250,
blit=True,
repeat_delay=0)
plt.show()
Сообщения об ошибках с python 3:
Traceback (most recent call last):
File "test.py", line 3, in <module>
import matplotlib.animation as animation
File "/home/arafat_hasan/.local/lib/python3.6/site-packages/matplotlib/animation.py", line 737, in <module>
class ImageMagickWriter(ImageMagickBase, MovieWriter):
File "/home/arafat_hasan/.local/lib/python3.6/site-packages/matplotlib/animation.py", line 120, in wrapper
if writerClass.isAvailable():
File "/home/arafat_hasan/.local/lib/python3.6/site-packages/matplotlib/animation.py", line 730, in isAvailable
return super().isAvailable()
File "/home/arafat_hasan/.local/lib/python3.6/site-packages/matplotlib/animation.py", line 427, in isAvailable
return shutil.which(cls.bin_path()) is not None
File "/home/arafat_hasan/.local/lib/python3.6/site-packages/matplotlib/animation.py", line 724, in bin_path
binpath = mpl._get_executable_info('magick').executable
File "/home/arafat_hasan/.local/lib/python3.6/site-packages/matplotlib/__init__.py", line 384, in _get_executable_info
return impl([path, "--version"], r"^Version: ImageMagick (\S*)")
File "/home/arafat_hasan/.local/lib/python3.6/site-packages/matplotlib/__init__.py", line 324, in impl
args, stderr=subprocess.STDOUT, universal_newlines=True)
File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib/python3.6/subprocess.py", line 425, in run
stdout, stderr = process.communicate(input, timeout=timeout)
File "/usr/lib/python3.6/subprocess.py", line 850, in communicate
stdout = self.stdout.read()
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 87: ordinal not in range(128)
Входные изображения :