English 中文(简体)
Py2exe d Python 脚本无法以 TIFF 格式保存图像
原标题:Py2exe d Python script cant save image in TIFF format

有一个 python 脚本 I m, 正在处理图像, 并将图像从 GIF 图像转换为扩展“.tif” 的 TIFF 格式...

剧本工作很好 甚至给了我正确的输出...

However, when i convert it into an exe using Py2exe(even tried Cx-Freeze) it is unable to save the processed image in TIFF format... it throws the following error:

保存 KeyError:. tif 中的“ PLimage. pyc” 文件, 第 1423 行

保存图像的代码 看起来像这个...

im_orig = Image.open(path1)
big = im_orig.resize((116, 56), Image.NEAREST)
ext = ".tif"
new=path.replace( . ,  ) 
newpath=new+"input-NEAREST"+ext
newimage=big.save(newpath)

我甚至试图更改上述代码如下,以避免“密钥错误”

im_orig = Image.open(path1)
big = im_orig.resize((116, 56), Image.NEAREST)
new=path.replace( . ,  ) 
newpath=new+"input-NEAREST.tif"
newimage=big.save(newpath, "TIFF" )

当我用剧本来运行代码时 代码的改变再次完全正常

但当我作为可执行文件运行脚本时会丢弃错误!

我得到的错误是:

PILImage.py", line 1429, in save
save_handler = SAVE[string.upper(format)] # unknown format
KeyError:  TIFF 

显然错误应该在此行中 :

newimage=big.save(newpath, "TIFF" )

将非常感激任何帮助或指导来解决这个问题。

问题回答

我认为问题在于 PIL 图像插件的初始化延迟。 一旦编译, 无法找到这些插件 。 解决方案是手动导入所需的插件 。 因此, 您需要的是

import TiffImagePlugin

我也有同样的问题,除了使用cx-freze而不是py2exe。Raja Selvaraj的解决方案为我固定了它。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签