Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python mac matplotlib imread错误_Python_Matplotlib - Fatal编程技术网

Python mac matplotlib imread错误

Python mac matplotlib imread错误,python,matplotlib,Python,Matplotlib,我正在尝试使用matplotlib的pyplot读取jpg图像 这是使用imread命令时出现的错误: Traceback (most recent call last): File "/Users/rugheid/Dropbox/Documents/Rugen Dropbox/School/Universiteit/3e jaar/P&O/Git Repository/backend/image_processing/image_processor.py", line 27, in &

我正在尝试使用matplotlib的pyplot读取jpg图像

这是使用imread命令时出现的错误:

Traceback (most recent call last):
File "/Users/rugheid/Dropbox/Documents/Rugen Dropbox/School/Universiteit/3e jaar/P&O/Git Repository/backend/image_processing/image_processor.py", line 27, in <module>
img = pyplot.imread(io.BytesIO(jpg_bytes), format='jpg')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py", line 2177, in imread
return _imread(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/image.py", line 1242, in imread
im = pilread(fname)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/image.py", line 1226, in pilread
return pil_to_array(image)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/image.py", line 1328, in pil_to_array
x = toarray(im)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/image.py", line 1313, in toarray
x_str = im.tostring('raw', im.mode)
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 695, in tostring
"Please call tobytes() instead.")
Exception: tostring() has been removed. Please call tobytes() instead.
回溯(最近一次呼叫最后一次):
文件“/Users/rughide/Dropbox/Documents/Rugen Dropbox/School/Universiteit/3e jaar/P&O/Git Repository/backend/image\u processing/image\u processor.py”,第27行,in
img=pyplot.imread(io.BytesIO(jpg_字节),format='jpg')
imread中的文件“/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/pyplot.py”,第2177行
返回_imread(*args,**kwargs)
imread中的文件“/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/image.py”,第1242行
im=pilread(fname)
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/image.py”,第1226行,pilread格式
将pil_返回到_数组(图)
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/image.py”,第1328行,在pil_-to_数组中
x=到阵列(im)
toarray中的文件“/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/image.py”,第1313行
x_str=im.tostring('raw',im.mode)
文件“/Library/Python/2.7/site packages/PIL/Image.py”,第695行,在tostring中
“请改为调用tobytes()”)
异常:tostring()已被删除。请改为调用tobytes()。
它似乎在调用已被删除的PIL中的某个内容。。。我可以把matplotlib改为使用枕头而不是PIL吗?或者我能做点别的吗?我安装了matplotlib的最新版本


提前谢谢

您可能应该直接使用,因为对于PNG文件以外的任何文件,
matplotlib
都会返回到
PIL
。发件人:

matplotlib只能本机读取PNG,但如果安装了PIL,它将使用它加载映像并返回数组(如果可能)

要使用
枕头加载JPG

from PIL import Image
im = Image.open('myimage.jpg')

通过这种方式,您可以删除中间人并直接控制图像加载。

您可能应该直接使用,因为对于PNG文件以外的任何文件,
matplotlib
都会返回到
PIL
。发件人:

matplotlib只能本机读取PNG,但如果安装了PIL,它将使用它加载映像并返回数组(如果可能)

要使用
枕头加载JPG

from PIL import Image
im = Image.open('myimage.jpg')
通过这种方式,您可以剪切中间人并直接控制图像加载