从包装内PIL打开图像

时间:2019-06-20 20:31:29

标签: python python-imaging-library python-importlib

我正在打包Python应用程序以供redist使用,并已在某些文件包中添加了manifest.in文件。

我正在尝试通过importlib.resources使用PIL打开这些资源,但是出现以下错误:

Traceback (most recent call last):
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\emojimage-1.0.0-py3.7.egg\emojimage\__main__.py", line 86, in <module>
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\emojimage-1.0.0-py3.7.egg\emojimage\__main__.py", line 77, in main
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\emojimage-1.0.0-py3.7.egg\emojimage\metafile.py", line 77, in generate_metafile
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PIL\Image.py", line 2705, in open
    % (filename if filename else fp))
OSError: cannot identify image file WindowsPath('C:/Users/me/AppData/Local/Temp/tmpue3cv9ob')

这是我用来访问文件的代码:

 with open(get_metafile_path(), 'w', newline='\n') as file:
        for x in resources.contents("emojimage.emoji"):
            with resources.path("emojimage.emoji", x) as p:
                image = Image.open(p)

任何线索为什么会失败?或者以其他方式在包装蛋中打开图像?

谢谢

0 个答案:

没有答案