Ugh, I thought we were done with this, but no.
So I moved my home workstation to Ubuntu 16.04 and lo and behold, we don't work there out-of-the-box. install.py gives ImportError: dynamic module does not define init function (PyInit_ycm_core)
Of course, I know how to fix this. The most trivial is to run python3 install.py <args> instead of just ./install.py <args>. We also have an entry in the FAQ with another workaround.
But it really must work out-of-the-box on the most frequently used Linux distro. We don't have much choice here; either it does and all is well in the world, or it doesn't and we'll get inundated with issue reports, no matter how well we document the issue.
The root of the problem is that despite reports that 16.04 will have system python default to python 3, that's wrong.
$ python --version
Python 2.7.11+
$ /usr/bin/env python --version
Python 2.7.11+
So it's still 2.7 as the default. BUT, the default vim is compiled against python 3! vim --version has -python and +python3.
The result is that running ./install.py makes it run inside a python 2 interpreter, which means that in that install file:
use_python2 = 'ON' if PY_MAJOR == 2 else 'OFF'
cmake_args.append( '-DUSE_PYTHON2=' + use_python2 )
so we end up compiling the libs against python 2. But then YCM uses sys.executable inside Vim (which points to python 3) to start ycmd, and that explodes.
@micbou @puremourning @vheon I'm looking for ideas on how best to address this, because we really must.
It' also occur this problem in my ubuntu16.04,but no one else solve the problem yet.
@linghutf Did you try to set the g:ycm_server_python_interpreter option to /usr/bin/python in your .vimrc?
let g:ycm_server_python_interpreter = '/usr/bin/python'
As @Valloric says
/usr/bin/python3 install.py args
works like a charm
let g:ycm_server_python_interpreter = '/usr/bin/python3' works well with me in Ubuntu Xenial Xerus....
@micbou @ehzShelter Are you sure?My environment is Ubuntu16.04 Desktop,The default python is python2.After adding the script in vimrc,problem hasn't be solved.
Could you run the command :YcmToggleLogs stderr in Vim and paste the contents of the logfile?
@linghutf ...Surely without any issue.. I have also run :YcmToggleLogs stderr
No error...!!
Make sure you have installed python3-dev
sudo apt-get install python3-dev
This is required to run install.py script via python3 interpreter
For confirmation >>

@ehzShelter This is my config:




Just as a hint for other Ubuntu users: If you run into errors, while using the _trivial fix_ of @Valloric:
python3 install.py <args>
, do not forget to install the python3-dev package, with:
sudo apt-get install python3-dev
mine is 16.04 it said the runit can't work,and the report shows everytime when i use the command of dpkg.i am a green hand in linux and language.don't know how to do.
Hello,
I am running Archlinux and I am still having the same problem even though I tried setting the g:ycm_python_binary_path to:
/usr/bin/python
and
/usr/bin/python2
and
/usr/bin/python3
I installed ycm_core by compiling it with the full installation guide:
cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/lib/libclang.so . ~/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/cpp
Thank you very much in advance for any help.
This is not the g:ycm_python_binary_path option but the g:ycm_server_python_interpreter one.
Oh sorry thank you
I followed @micbou 's instruction to set g:ycm_server_python_interpreter and it works for my Python 2 environment on 16.04!
well actually i klone another vimrc from my friend and i wonder if i still use yours will it cause problems anyway i just want to remove
and also my system has reported errror i don't know whether it is nessary to solve it. and how
green hand is hard to work on not only on vimrc and system but github
maybe it's not suit me
@chenshuxian1997 I don't understand what you mean. Could you write in Chinese instead?
@linghutf, @micbou solution works!
Put this in your .vimrc: let g:ycm_server_python_interpreter = '/usr/bin/python'
$ git clone https://github.com/Valloric/YouCompleteMe.git
$ git checkout -> master(default)
$ ./install.py <args>
@starrysl 看样子我的英语真的很差...言归正传,就是我后来用了朋友vim配置,导致每次更新都会显示runit没配置,后来我就直接手动找到文件路径删除文件夹,应该没问题吧
Hello!
Why is this issue closed? It is not working out of the box. I run Ubuntu 16.04. I got the Error in the log: ERROR - ycm_core library compiled for Python 2 but loaded in Python 3.
This issue -at least- should be properly reflected in the installation guide. Which it is not.
Greetings
log: ERROR - ycm_core library compiled for Python 2 but loaded in Python 3.
@Thilo1 should we be more specific? I mean the error is telling you what is happening 😕
I am not complaining about the specifity of the error message 😉. My wish would be more verbosity.
Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet.Am 14.10.16, 23:41, Andrea Cedraro [email protected] schrieb:
log: ERROR - ycm_core library compiled for Python 2 but loaded in Python 3.
@Thilo1 should we be more specific? I mean the error is telling you what is happening 😕
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
@Thilo1 Did you use the install.py script to install YCM? Are you seeing this message
The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library compiled for Python 2 but loaded in Python 3. Set the 'g:ycm_server_python_interpreter' option to a Python 2 interpreter path.
in Vim?
Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet.Am 15.10.16, 00:12, micbou [email protected] schrieb:
@Thilo1 Did you use the install.py script to install YCM? Are you seeing this message
The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library compiled for Python 2 but loaded in Python 3. Set the 'g:ycm_server_python_interpreter' option to a Python 2 interpreter path.
in Vim?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
@Thilo1 use the install.py script, is easier and more errorproof. @micbou I think you were right and we should move the "Full installation guide" as a last resort thing 😕
Same issue as above. Had to explicitly use python3 (as others suggested) in order to get the install script working:
python3 ./install.py --clang-completer
Python2 generated a compilation error.
Also make sure to add to your .vimrc file:
let g:ycm_server_python_interpreter = '/usr/bin/python3'
@michaelachrisco thank you very much! i tried it all day... now it works.
@michaelachrisco thank you very much! i tried it for nearly 2 hours... now it works.
Most helpful comment
@linghutf Did you try to set the
g:ycm_server_python_interpreteroption to/usr/bin/pythonin your.vimrc?