Python图像库可以';t转换为pdf格式

Python图像库可以';t转换为pdf格式,python,pdf,python-imaging-library,pillow,Python,Pdf,Python Imaging Library,Pillow,我有一个功能,将bmp转换为pdf与枕头,这个脚本我有它在非编译版本和编译版本(.exe)。在第一个示例中,它工作正常,但在第二个示例中,它抛出了一个异常('PDF')。在.save()中特别失败 扩展名为的路径和文件名正确 from PIL import Image def bmp2pdf(self, file): ''' Convert a bmp file to PDF file, and delete old bmp file ''' img = Image.open(f

我有一个功能,将bmp转换为pdf与枕头,这个脚本我有它在非编译版本和编译版本(.exe)。在第一个示例中,它工作正常,但在第二个示例中,它抛出了一个异常('PDF')。在.save()中特别失败 扩展名为的路径和文件名正确

from PIL import Image
def bmp2pdf(self, file):
    ''' Convert a bmp file to PDF file, and delete old bmp file '''
    img = Image.open(file)
    output = file.replace('.bmp', '.pdf')
    try:
        img.save(output, "PDF", resolution=100.0)
        remove(file)
    except Exception as err:
        print(err)
在编译版本中,输出为:

'PDF'

Thx.

遵循此代码。它可以工作。3行代码

从PIL导入图像
def bmp2pdf(自身,路径):
img=Image.open(路径)
img.save('image.pdf','pdf')


我得到了一个名为image.pdf的文件,其中包含图像。

我必须在我的设置中添加生成.exe,我应该导入PIL而不是PIL.image,因此整个模块都已加载,pdf功能可用

我正在使用cx\U冻结:

'Packages': [
    'PyQt5.uic',
    "...",
    'PIL',
]

什么是完全异常?以什么方式编译?你把依赖项打包了吗?我用CX\u freeze来编译。我已经导入了:'PIL.Image'。是的,但是如果你看我的代码,就会发现我从系统中删除了bmp。它对我有用。.exe中唯一的东西不是!