@@ -61,7 +61,9 @@ def __getattr__(self, id):
6161
6262except ImportError as v :
6363 core = _imaging_not_installed ()
64- if str (v )[:20 ] == "Module use of python" and warnings :
64+ if not warnings : # the warnings module is available since Python 2.1
65+ raise # raise the original ImportError.
66+ elif str (v ).startswith ("Module use of python" ):
6567 # The _imaging C module is present, but not compiled for
6668 # the right version (windows only). Print a warning, if
6769 # possible.
@@ -70,8 +72,25 @@ def __getattr__(self, id):
7072 "of Python; most PIL functions will be disabled" ,
7173 RuntimeWarning
7274 )
73- if str (v ).startswith ("The _imaging extension" ) and warnings :
75+ elif str (v ).startswith ("The _imaging extension" ):
7476 warnings .warn (str (v ), RuntimeWarning )
77+ elif "Symbol not found: _PyUnicodeUCS2_FromString" in str (v ):
78+ warnings .warn (
79+ "The _imaging extension was build for Python with UCS2 support; "
80+ "recompile PIL or build Python --without-wide-unicode. "
81+ "Most PIL functions will be disabled" ,
82+ RuntimeWarning
83+ )
84+ elif "Symbol not found: _PyUnicodeUCS4_FromString" in str (v ):
85+ warnings .warn (
86+ "The _imaging extension was build for Python with UCS4 support; "
87+ "recompile PIL or build Python --with-wide-unicode. "
88+ "Most PIL functions will be disabled" ,
89+ RuntimeWarning
90+ )
91+ else :
92+ # unknown problem. Raise the original exception.
93+ raise
7594
7695try :
7796 import builtins
0 commit comments