@@ -498,40 +498,55 @@ def register_readline():
498498PYTHON_BASIC_REPL = False
499499
500500import atexit
501+
502+ try :
503+ try :
504+ import readline
505+ except ImportError :
506+ readline = None
507+ else :
508+ import rlcompleter # noqa: F401
509+ except ImportError :
510+ return
511+
501512try :
502- import readline
503- import rlcompleter # noqa: F401
504513if PYTHON_BASIC_REPL :
505514CAN_USE_PYREPL = False
506515else :
507516original_path = sys .path
508517sys .path = [p for p in original_path if p != '' ]
509518try :
510519import _pyrepl .readline
511- import _pyrepl .unix_console
520+ if os .name == "nt" :
521+ import _pyrepl .windows_console
522+ console_errors = (_pyrepl .windows_console ._error ,)
523+ else :
524+ import _pyrepl .unix_console
525+ console_errors = _pyrepl .unix_console ._error
512526from _pyrepl .main import CAN_USE_PYREPL
513527finally :
514528sys .path = original_path
515529except ImportError :
516530return
517531
518- # Reading the initialization (config) file may not be enough to set a
519- # completion key, so we set one first and then read the file.
520- if readline .backend == 'editline' :
521- readline .parse_and_bind ('bind ^I rl_complete' )
522- else :
523- readline .parse_and_bind ('tab: complete' )
532+ if readline is not None :
533+ # Reading the initialization (config) file may not be enough to set a
534+ # completion key, so we set one first and then read the file.
535+ if readline .backend == 'editline' :
536+ readline .parse_and_bind ('bind ^I rl_complete' )
537+ else :
538+ readline .parse_and_bind ('tab: complete' )
524539
525- try :
526- readline .read_init_file ()
527- except OSError :
528- # An OSError here could have many causes, but the most likely one
529- # is that there's no .inputrc file (or .editrc file in the case of
530- # Mac OS X + libedit) in the expected location. In that case, we
531- # want to ignore the exception.
532- pass
540+ try :
541+ readline .read_init_file ()
542+ except OSError :
543+ # An OSError here could have many causes, but the most likely one
544+ # is that there's no .inputrc file (or .editrc file in the case of
545+ # Mac OS X + libedit) in the expected location. In that case, we
546+ # want to ignore the exception.
547+ pass
533548
534- if readline .get_current_history_length ()== 0 :
549+ if readline is None or readline .get_current_history_length ()== 0 :
535550# If no history was loaded, default to .python_history,
536551# or PYTHON_HISTORY.
537552# The guard is necessary to avoid doubling history size at
@@ -542,8 +557,10 @@ def register_readline():
542557
543558if CAN_USE_PYREPL :
544559readline_module = _pyrepl .readline
545- exceptions = (OSError ,* _pyrepl . unix_console . _error )
560+ exceptions = (OSError ,* console_errors )
546561else :
562+ if readline is None :
563+ return
547564readline_module = readline
548565exceptions = OSError
549566