Getting path to python exe on Windows correctly

Fixes #581.
This commit is contained in:
Strahinja Val Markovic 2013-10-11 11:11:02 -07:00
parent 78e3607b00
commit db45e243dd
2 changed files with 30 additions and 3 deletions

View File

@ -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,

View File

@ -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 ),