@@ -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,26 @@ 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 : # pragma: no cover
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+ vt100_support = sys .stdout .isatty ()
129+
130+ # Check if readline was loaded
131+ if rl_type == RlType .NONE : # pragma: no cover
132+ if not _rl_warn_reason :
133+ _rl_warn_reason = ("no supported version of readline was found. To resolve this, install\n "
134+ "pyreadline on Windows or gnureadline on Mac." )
135+ rl_warning = ("Readline features including tab completion have been disabled because\n "
136+ + _rl_warn_reason + '\n \n ' )
137+ else :
138+ rl_warning = ''
125139
126140
127141# noinspection PyProtectedMember,PyUnresolvedReferences
0 commit comments