3434DEBUG_PORT = None
3535SERVER_DEBUGGING = False
3636
37+ LAST_ERROR_TIME = None
3738
3839# Constants
3940SERVER_SCRIPT = os .path .join (
@@ -325,29 +326,22 @@ def proxy_for(view):
325326 will automatically create a new proxy if none exists for the
326327 requested interpreter'''
327328 proxy = None
329+
330+ python_detectors = [
331+ lambda : normalize_path (get_setting ("python_interpreter" , view , "" ), True ),
332+ lambda : normalize_path (project_venv_python (view )),
333+ lambda : normalize_path (shebang_line_python (view )),
334+ lambda : normalize_path (system_python ())
335+ ]
328336 with PROXY_LOCK :
329- python = normalize_path (get_setting ("python_interpreter" , view , "" ), True )
330- if not python :
331- python = normalize_path (project_venv_python (view ))
332- if not python :
333- python = normalize_path (shebang_line_python (view ))
334- if not python :
335- python = normalize_path (system_python ())
337+ for detector in python_detectors :
338+ python = detector ()
339+ if python is not None :
340+ break
336341
337342 if not python or not os .path .exists (python [0 ]):
338- raise OSError ("""
339- --------------------------------------------------------------------------------------------------------------
340- Could not detect python, please set the python_interpreter (see README) using an absolute path or make sure a
341- system python is installed and is reachable on the PATH. Here is the order in which paths are tried:
342-
343- - By "python_interpreter" Sublime settings: %r
344- - By auto-detecting venv: %r
345- - By #! (shebang) line in this file: %r
346- - By auto-detecting system Python: %r
347-
348- We use the first non-None value and ensure that the path exists before proceeding.
349- --------------------------------------------------------------------------------------------------------------"""
350- % pythons )
343+ show_python_not_found_error (python_detectors )
344+ return
351345
352346 # Since lists cannot be used as keys, a temporary tuple version of this is created.
353347 python_as_key = tuple (python )
@@ -363,6 +357,27 @@ def proxy_for(view):
363357 return proxy
364358
365359
360+ def show_python_not_found_error (python_detectors ):
361+ if LAST_ERROR_TIME is None or (time .time () - LAST_ERROR_TIME > 10.0 ):
362+ do_not_show_again = sublime .ok_cancel_dialog ("""
363+ Could not detect python, please set the python_interpreter (see README) using an absolute path or make sure a
364+ system python is installed and is reachable on the PATH. Here is the order in which paths are tried:
365+
366+ - By "python_interpreter" Sublime settings: %r
367+ - By auto-detecting venv: %r
368+ - By #! (shebang) line in this file: %r
369+ - By auto-detecting system Python: %r
370+
371+ We use the first non-None value and ensure that the path exists before proceeding.
372+ """ % tuple (d () for d in python_detectors ), "Do not show again" )
373+
374+ global LAST_ERROR_TIME
375+ if do_not_show_again :
376+ LAST_ERROR_TIME = float ("inf" )
377+ else :
378+ LAST_ERROR_TIME = time .time ()
379+
380+
366381def root_folder_for (view ):
367382 '''returns the folder open in ST which contains
368383 the file open in this view. Used to determine the
0 commit comments