2016-09-16 49 views
0

我试图从python2转换为python3的程序使用PIL python图像库。将python2 PIL转换为python3代码

我尝试从网上下载缩略图以在tkinter样式gui中显示。这是,我认为,问题的代码行:

# grab the thumbnail jpg. 
req = requests.get(video.thumb) 
photo = ImageTk.PhotoImage(Image.open(StringIO(req.content))) 

# now this is in PhotoImage format can be displayed by Tk. 
plabel = tk.Label(tf, image=photo) 
plabel.image = photo 
plabel.grid(row=0, column=2) 

程序停止,并给出了类型错误,这里是backtrce:

Traceback (most recent call last): File "/home/kreator/.local/bin/url-launcher.py", line 281, in <module> 
    main() 
    File "/home/kreator/.local/bin/url-launcher.py", line 251, in main 
    runYoutubeDownloader() 
    File "/home/kreator/.local/bin/url-launcher.py", line 210, in runYoutubeDownloader 
    photo = ImageTk.PhotoImage(Image.open(StringIO(req.content))) 
    TypeError: initial_value must be str or None, not bytes 

我如何满足这里python3的要求是什么?

+0

http://stackoverflow.com/questions/31064981/python3-error-initial-value-must-be-str-or-none可能的重复 – ymonad

回答

2

在这种情况下,您可以看到您导入的库不支持Python3。这不是你可以在自己的代码中修复的东西。

缺乏Python3支持是因为PIL已经停用了相当长一段时间了。有一个叉积极维护,我会建议您使用,而不是:https://pillow.readthedocs.io/

您可以从pypi下载它。