ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.44k stars 2.81k forks source link

YouCompleteMe unavailable: Could not find standard library path in Python path. #2293

Closed sassanh closed 8 years ago

sassanh commented 8 years ago

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your issue:

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

Vim version:

NVIM 0.1.4
Build type: RelWithDebInfo
Compilation: /usr/local/Library/ENV/4.3/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/build/config -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/src -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/deps-build/usr/include -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/deps-build/usr/include -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/deps-build/usr/include/luajit-2.0 -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/deps-build/usr/include -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/deps-build/usr/include -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/deps-build/usr/include -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/deps-build/usr/include -I/usr/local/opt/gettext/include -I/usr/include -I/usr/include -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/build/src/nvim/auto -I/tmp/neovim-20160524-70013-14wksgv/neovim-0.1.4/build/include
Compiled by sassanharadji@MacBook-Pro

Optional features included (+) or not (-): +acl   +iconv    +jemalloc
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.1.4/share/nvim"

OS X El Capitan

After updating to latest version ycm, when I run vim in a virtualenv I get this error:

YouCompleteMe unavailable: Could not find standard library path in Python path.

The virtualenv is using python3 and I guess it's the problem. YCM is trying to read "python2-7" libraries in the lib folder of the python3 in the virtualenv.

micbou commented 8 years ago

Thanks for the report. What is the output of the command:

:py3 import pprint; pprint.pprint( sys.path )

in Neovim?

sassanh commented 8 years ago

Thanks for quick reply, this is the output:

['/Users/sassanharadji/.config/nvim/plugged/jedi-vim',
 '/Users/sassanharadji/.virtualenvs/x/lib/python3.5/site-packages/Babel-2.4.0.dev0-py3.5.egg',
 '/Users/sassanharadji/.virtualenvs/x/lib/python35.zip',
 '/Users/sassanharadji/.virtualenvs/x/lib/python3.5',
 '/Users/sassanharadji/.virtualenvs/x/lib/python3.5/plat-darwin',
 '/Users/sassanharadji/.virtualenvs/x/lib/python3.5/lib-dynload',
 '/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
 '/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
 '/Users/sassanharadji/.virtualenvs/x/lib/python3.5/site-packages',
 '_vim_path_',
 '/Users/sassanharadji/.config/nvim/plugged/vim-virtualenv/autoload']
micbou commented 8 years ago

And the output of:

:py3 from distutils import sysconfig; print( sysconfig.get_python_lib( standard_lib = True ) )

?

sassanh commented 8 years ago
/Users/sassanharadji/.virtualenvs/x/bin/../lib/python3.5
micbou commented 8 years ago

Ok, applying os.path.normpath on this line should fix your issue. I am just a little surprised that get_python_lib returns a path with /../ in it. Which tool are you using to create your virtual environment? I can't reproduce this kind of path with the virtualenv package from pip.

Anyway, I'll send a PR to fix this.

sassanh commented 8 years ago

It didn't fix the issue, value of standard_library_path after than line is "/Users/sassanharadji/.virtualenvs/x/lib/python2.7" but this directory does not exist, the one that exists is "/Users/sassanharadji/.virtualenvs/x/lib/python3.5" which is for python 3.5.

sassanh commented 8 years ago

I guess ycm is not running with py3, seems like it's running with py.

micbou commented 8 years ago

Then what is the output of the two previous commands with py instead of py3?

sassanh commented 8 years ago

First one:

[u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/OmniSharpServer',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/godef',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/gocode',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/frozendict',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/bottle',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/argparse',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/retries',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/requests-futures',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/pythonfutures',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/python/ycm/../../third_party/ycmd',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/autoload/../python',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/OmniSharpServer',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/godef',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/gocode',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/frozendict',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/bottle',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd/third_party/argparse',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/ycmd',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/retries',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/requests-futures',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/third_party/pythonfutures',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/python/ycm/../../third_party/ycmd',
 u'/Users/sassanharadji/.config/nvim/plugged/YouCompleteMe/autoload/../python',
 '/Users/sassanharadji/.virtualenvs/x/lib/python2.7/site-packages',
 '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/Users/sassanharadji/Library/Python/2.7/lib/python/site-packages',
 '/usr/local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages/gtk-2.0',
 '/usr/local/lib/python2.7/site-packages/wx-3.0-osx_cocoa',
 '/usr/local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages/gtk-2.0',
 '/usr/local/lib/python2.7/site-packages/gtk-2.0',
 '/usr/local/lib/python2.7/site-packages/wx-3.0-osx_cocoa',
 '/Library/Python/2.7/site-packages',
 '_vim_path_',
 '/Users/sassanharadji/.config/nvim/plugged/vim-virtualenv/autoload',
 '/Users/sassanharadji/.config/nvim/plugged/MatchTagAlways/autoload/../python']

Second one:

/Users/sassanharadji/.virtualenvs/x/lib/python2.7
sassanh commented 8 years ago

@micbou I found that if I disable vim-virtualenv plugin, everything works alright as before. Seems like the problem is with that plugin, though ycm didn't have any problems with it till the latest version.

micbou commented 8 years ago

I can reproduce your issue with the vim-virtualenv plugin. I've sent PR https://github.com/Valloric/ycmd/pull/579 to fix the issue.

Note that the :VirtualEnvDeactivate command from vim-virtualenv plugin remove paths that were added by YCM in sys.path so it may break YCM. Use with care. See issue https://github.com/jmcantrell/vim-virtualenv/issues/53.

sassanh commented 8 years ago

Thanks following this up with me, your pr and info.

gbataille commented 8 years ago

I'm having this issue still with the latest ycm (commit d38ffc54461963c4495fefdd8b0c3d706f72d957) I do not have vim-virtualenv

However, I have this bit in my .vimrc

"########################
"####### Python #########
"########################
" python with virtualenv support
py << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
  project_base_dir = os.environ['VIRTUAL_ENV']
  activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
  execfile(activate_this, dict(__file__=activate_this))
EOF

let python_highlight_all=1
let g:ycm_python_binary_path = '/usr/local/bin/python'

seeing this code (that I blindly pasted from some SO post :) ) I can see that me forcing the python path to the brew installed python (important to not use python 3 for me) is a bit inconsistent with the virtualenv setup. I don't know if that could explain my issue (does not seem so, if I remove it I get the same result. does not work. But works with the patch)

I did not quite follow the end of your discussion but I have for the moment successfully applied @micbou patch from there