Python Cython生成的Executable显示导入错误

时间:2015-05-17 22:36:18

标签: python gcc cython importerror

我最近学会了如何编译cython到exe,我正在尝试编译一个简单的gui练习脚本(我是新手)

import sys,os
import msvcrt,Image,ImageTk
import Tkinter as Tk
import ttk,io,subprocess
msvcrt.setmode(sys.stdin.fileno(),os.O_BINARY)
#data=sys.stdin.read()
def callback():
    contrast=subprocess.Popen('conv out.jpg -brightness-contrast 30x10 -resize 350x PNG:-',shell=1,stdout=subprocess.PIPE).communicate()[0]
    contrast=io.BytesIO(contrast)
    photo=Image.open(contrast).copy().resize((350,350))
    preview.imo=ImageTk.PhotoImage(photo)
    preview.config(image=preview.imo)
m=Tk.Tk()
#conv mkchoice.jpg -brightness-contrast 10x30 out.jpg
m.title('Editor')
op=ImageTk.PhotoImage(Image.open('mkchoice.jpg').resize((350,350)))
original=Tk.Label(m,text="Original",image=op)
original.pack()
preview=Tk.Label(m,text="Preview",image=op)
preview.pack(side='left')
button=ttk.Button(m,text="Contrast",command=callback)
button.pack()
m.mainloop()

脚本编译为exe就好了,但exe在执行时会出现导入错误

Traceback (most recent call last):
  File "std.py", line 16, in init std (std.c:1518)
    op=ImageTk.PhotoImage(Image.open('mkchoice.jpg').resize((350,350)))
  File "C:\Python\lib\site-packages\PIL\Image.py", line 1290, in resize
    self.load()
  File "C:\Python\lib\site-packages\PIL\ImageFile.py", line 164, in load
    self.load_prepare()
  File "C:\Python\lib\site-packages\PIL\ImageFile.py", line 231, in load_prepare

    self.im = Image.core.new(self.mode, self.size)
  File "C:\Python\lib\site-packages\PIL\Image.py", line 37, in __getattr__
    raise ImportError("The _imaging C module is not installed")
ImportError: The _imaging C module is not installed

我认为它需要来自PIL目录的_imaging.pyd文件,但我不知道如何包含它

我的gcc命令ATM

gcc %gcp% %out:.py=.c% -I"C:\python\include" -L"C:\Python\libs" -lpython27 -o %out:.py=%.exe

0 个答案:

没有答案