diff --git a/python/ycm/utils.py b/python/ycm/utils.py index 28fa7d05..5d2281e4 100644 --- a/python/ycm/utils.py +++ b/python/ycm/utils.py @@ -23,6 +23,10 @@ import sys import signal import functools +WIN_PYTHON27_PATH = 'C:\python27\pythonw.exe' +WIN_PYTHON26_PATH = 'C:\python26\pythonw.exe' + + def IsIdentifierChar( char ): return char.isalnum() or char == '_' @@ -44,9 +48,33 @@ def PathToTempDir(): return tempdir +def PathToPythonInterpreter(): + # This is a bit tricky. Normally, sys.executable has the full path to the + # Python interpreter. But this code is also executed from inside Vim's + # embedded Python. On Unix machines, even that Python returns a good value for + # sys.executable, but on Windows it returns the path to the Vim binary, which + # is useless to us (issue #581). So we check the common install location for + # Python on Windows, first for Python 2.7 and then for 2.6. + # + # I'm open to better ideas on how to do this. + + if OnWindows(): + if os.path.exists( WIN_PYTHON27_PATH ): + return WIN_PYTHON27_PATH + elif os.path.exists( WIN_PYTHON26_PATH ): + return WIN_PYTHON26_PATH + raise RuntimeError( 'Python 2.7/2.6 not installed!' ) + else: + return sys.executable + + +def OnWindows(): + return sys.platform == 'win32' + + # From here: http://stackoverflow.com/a/8536476/1672783 def TerminateProcess( pid ): - if sys.platform == 'win32': + if OnWindows(): import ctypes PROCESS_TERMINATE = 1 handle = ctypes.windll.kernel32.OpenProcess( PROCESS_TERMINATE, diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 43a5db1a..abc802e8 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -20,7 +20,6 @@ import os import vim import subprocess -import sys import tempfile import json from ycm import vimsupport @@ -62,7 +61,7 @@ class YouCompleteMe( object ): with tempfile.NamedTemporaryFile( delete = False ) as options_file: self._temp_options_filename = options_file.name json.dump( dict( self._user_options ), options_file ) - args = [ sys.executable, + args = [ utils.PathToPythonInterpreter(), _PathToServerScript(), '--port={0}'.format( server_port ), '--options_file={0}'.format( options_file.name ),