2016-09-16 7 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) 

プログラムは例外TypeErrorを停止しています、ここ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からダウンロードできます。

関連する問題