Closed ray-x closed 8 years ago
I don't have the answer to your problem right now but to specify the python CMake should use you can set the EXTRA_CMAKE_ARGS
env variable passing -DPYTHON_LIBRARY=...
But the more important question is why do you want to build ycmd with Python3? If you have Python2 the functionality don't change.
Thanks Vhen for suggest -DPYTHON_LIBRARY. Current YCM doing a good job for the library in system path (python 2.7.10 site-packages). While I have multiple virtualenv runs 2.7, 3.4 and 3.5. Cross py2 and py3 will cause ycmd crash so it be better for me to build a py3 specific ycmd. But seems it take a while doing so on Mac. One of the dirty hack would copy a python3.5-config to virtualenv bin dir and make a link to python-config. But for those new to build ycmd, would still be good to have a better way to fix.
We have to be clear of which python interpreter is used and for what because unfortunately we have more than one here: When you build YCM we're actually building the ycmd
server because since https://github.com/Valloric/YouCompleteMe/commit/fd0c2cc1d8efe7d7f74ee39271be3e14c23ff85c YCM is not importing anymore the compiled library which makes it independent from the version you're building the library; in other word you can compile the ycmd
server with Python3 but use the client under Python2. When we say "the client" here we're talking about the vim plugin YCM and with regard to Python is the Python bindings that vim uses. Now you're talking about virtualenv so I assume that you use YCM to work on some Python project using the jedi-backed semantic engine. For a long time the jedi used by YCM used the same Python interpreter used by the ycmd
server which meant "no Python3 support". Now at least since https://github.com/Valloric/YouCompleteMe/pull/1928 is possible to specify under which interpreter to run jedi (through the JediHTTP wrapper) so we is possible a situation like:
(YCM) Python 3.3 ---> (ycmd) Python 2.6 ---> (JediHTTP) Python 3.5
But to do this some configuration is needed because by default the ycmd
server will be spawned using the same Python interpreter used by the YCM client and JediHTTP
will be spawned using the same Python interpreter used by the ycmd
server. So if you compiled the ycmd
server using Python2 but the vim client tries to spawn it using Python3 ycmd
will crash. So to achieve the configuration that I've showed before you'd have to set:
let g:ycm_path_to_python_interpreter = /path/to/python2.6
let g:ycm_python_binary_path = /path/to/python3.5
assuming you have vim compiled against the Python3.3 interpreter.
TL;DR; You don't need to compile YCM with the same python version as the one you want completion for or the one used by vim, just use the right settings to tell which Python to use for what :+1:
And is all in the docs :smiley:
I hope I was of any help understand what is going on, if not for you because you already knew those things for anyone who will pass by :stuck_out_tongue_closed_eyes:
let g:ycm_path_to_python_interpreter = /path/to/python2.6 let g:ycm_python_binary_path = /path/to/python3.5
Seeing these options like this side-by-side, IMO it's pretty obvious we should rename them. Probably to ycm_ycmd_python_interpreter
and ycm_jedihttp_python_interpreter
. We can fall back on the old names for the sake of backwards compatibility. The description of these options should probably be updated as well.
@vheon Would you like to send a PR for the above? :)
I rebuild ycm with system default python (2.7) and set vimrc as following:
let g:ycm_path_to_python_interpreter = '/usr/bin/python' let g:ycm_python_binary_path = '/home/ray/projects/python/py3env/bin/python3'
It works great !
@vheon Would you like to send a PR for the above? :)
Sure :+1:
It works great !
Then I'm going to close this :wink:
OS MacOS EI-C (10.11.3)
1) How Python was installed: brew install python3 --framework --universal
2) what fails: python3 install.py failed because build.py will search /usr/lib/libpython2.7
Issue was caused by build.py CustomPythonCmakeArgs :
def CustomPythonCmakeArgs():
The CMake 'FindPythonLibs' Module does not work properly.
So we are forced to do its job for it.
print( 'Searching for python libraries...' ) python_prefix = CheckOutput( [ 'python-config', '--prefix' ] ).strip().decode( 'utf8' )
Even I run install.py with /usr/local/bin/python3.5 this command still will point to default python 2.7 installed in Mac. So the following script will looking for /usr/lib/libpython2.7 instead of 3.5. It also not working if I using inside a virtualenv. Because virtualenv will only install python3.5-config instead of python-config in PATH
Possible solution for this is either using python3-config:
python3-config --prefix
/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5
This will point to correct library installed.
BTW, This issue is also why sometimes brew failed to build python3 package for openCV3
Issue Prelude
Please complete these steps and check these boxes (by putting an
x
inside the brackets) before filing your issue:vim --version
.:YcmDebugInfo
.:YcmToggleLogs stderr
.Thank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.
Issue Details
[If filing a bug report, please include a list of steps that describe how to reproduce the bug you are experiencing. Also include test code if relevant.]