@@ -32,6 +32,9 @@ class RlType(Enum):
3232# Tells if the terminal we are running in supports vt100 control characters
3333vt100_support = False
3434
35+ # Explanation for why readline wasn't loaded
36+ _rl_warn_reason = ''
37+
3538# The order of this check matters since importing pyreadline will also show readline in the modules list
3639if 'pyreadline' in sys .modules :
3740 rl_type = RlType .PYREADLINE
@@ -113,15 +116,27 @@ def pyreadline_remove_history_item(pos: int) -> None:
113116elif 'gnureadline' in sys .modules or 'readline' in sys .modules :
114117 # We don't support libedit
115118 if 'libedit' not in readline .__doc__ :
116- rl_type = RlType .GNU
117-
118- # Load the readline lib so we can access members of it
119- import ctypes
120- readline_lib = ctypes .CDLL (readline .__file__ )
121-
122- # Check if we are running in a terminal
123- if sys .stdout .isatty ():
124- vt100_support = True
119+ try :
120+ # Load the readline lib so we can access members of it
121+ import ctypes
122+ readline_lib = ctypes .CDLL (readline .__file__ )
123+ except AttributeError :
124+ _rl_warn_reason = ("this application is running in a non-standard Python environment in\n "
125+ "which readline is not loaded dynamically from a shared library file" )
126+ else :
127+ rl_type = RlType .GNU
128+ if sys .stdout .isatty ():
129+ vt100_support = True
130+
131+ # Check if readline was loaded
132+ if rl_type == RlType .NONE :
133+ if not _rl_warn_reason :
134+ _rl_warn_reason = ("no supported version of readline was found. To resolve this, install\n "
135+ "pyreadline on Windows or gnureadline on Mac." )
136+ rl_warning = ("Readline features including tab completion have been disabled because\n " +
137+ _rl_warn_reason + '\n \n ' )
138+ else :
139+ rl_warning = ''
125140
126141
127142# noinspection PyProtectedMember,PyUnresolvedReferences
0 commit comments