From 29b2c6e23dc98cd941ae7cca9f65041855143b09 Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 4 Jul 2018 18:43:39 +0300 Subject: [PATCH] Only import cffi where needed, to avoid problems with PYTHONOPTIMIZE=2 --- src/PIL/ImageTk.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index 17bf32f62..d58ee8528 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -32,13 +32,6 @@ if sys.version_info.major > 2: else: import Tkinter as tkinter -# required for pypy, which always has cffi installed -try: - from cffi import FFI - ffi = FFI() -except ImportError: - pass - from . import Image from io import BytesIO @@ -192,7 +185,11 @@ class PhotoImage(object): from . import _imagingtk try: if hasattr(tk, 'interp'): - # Pypy is using a ffi cdata element + # Required for PyPy, which always has CFFI installed + from cffi import FFI + ffi = FFI() + + # Pypy is using an FFI cdata element # (Pdb) self.tk.interp # _imagingtk.tkinit(