JBakamovic / yavide

Modern C/C++ integrated development environment
GNU General Public License v2.0
1.3k stars 137 forks source link

Cannot find attribute 'clang.cindex.BaseEnumeration' #74

Open NicolasAubinet opened 7 years ago

NicolasAubinet commented 7 years ago

Hello,

I'm having trouble getting Yavide to run correctly. I first had issues about watchdog and found i had to run "pip2.7 install watchdog" to get rid of that error, but now I'm having a similar issue on yavide that can't find clang.cindex.BaseEnumeration. I'm not too good at Python, but there is nothing named BaseEnumeration in the clang/cindex.py file. Doing a grep on BaseEnumeration in the yavide folder only shows the clang_parser.py file that tries to access it but can't find it. Running "pip2.7 install clang" also doesn't seem to fix the issue.

Here is the full error output:

Error detected while processing function Y_Env_Init[2]..Y_ServerStart:
line    8:
Traceback (most recent call last):
Press ENTER or type command to continue
Error detected while processing function Y_Env_Init[2]..Y_ServerStart:
line    8:
  File "<string>", line 1, in <module>
Press ENTER or type command to continue
Error detected while processing function Y_Env_Init[2]..Y_ServerStart:
line    8:
  File "/opt/yavide/core/server/yavide_server.py", line 8, in <module>
Press ENTER or type command to continue
Error detected while processing function Y_Env_Init[2]..Y_ServerStart:
line    8:
    from services.source_code_model_service import SourceCodeModel
Press ENTER or type command to continue
Error detected while processing function Y_Env_Init[2]..Y_ServerStart:
line    8:
  File "/opt/yavide/core/services/source_code_model_service.py", line 3, in <module>
Press ENTER or type command to continue
Error detected while processing function Y_Env_Init[2]..Y_ServerStart:
line    8:
    from services.parser.clang_parser import ClangParser
Press ENTER or type command to continue
Error detected while processing function Y_Env_Init[2]..Y_ServerStart:
line    8:
  File "/opt/yavide/core/services/parser/clang_parser.py", line 7, in <module>
Press ENTER or type command to continue
Error detected while processing function Y_Env_Init[2]..Y_ServerStart:
line    8:
    class ChildVisitResult(clang.cindex.BaseEnumeration):
Press ENTER or type command to continue
Error detected while processing function Y_Env_Init[2]..Y_ServerStart:
line    8:
AttributeError: 'module' object has no attribute 'BaseEnumeration'

Can anyone help me to fix this?

Thanks!

JBakamovic commented 7 years ago

Hi, sorry for a bit delayed reply.

BaseEnumeration should indeed be part of the cindex.py file. I am not sure why would you not have it there. Perhaps an not up to date version of libclang and/or its Python bindings? What system do you run?

Try to update the libclang version and its Python bindings and let us know if it helped.

Cheers, Adi

NicolasAubinet commented 7 years ago

Hello, no problem, thank you for replying.

I'm running on Gentoo. I assumed that cindex.py came from yavide itself, or that it was trying to find it somewhere else. But reading that the file was supposed to define BaseEnumeration led me to compare the cindex.py from yavide/core/external/clang_complete/plugin/clang/cindex.py and the one installed by the clang-python package, and I found that they were not exactly the same. The one installed by clang-python defines BaseEnumeration as expected, but not the one from the yavide installation folder.

I tried to copy all the files from /usr/lib64/python2.7/site-packages/clang (the clang-python package files) to the yavide installation folder in yavide/core/external/clang_complete/plugin/clang/ and that fixed it! I'm now running yavide successfully!

Thanks a lot!

JBakamovic commented 7 years ago

Hm, the way you fixed the issue does not really correspond to the error message which you have attached above or perhaps I am not reading it well. clang_complete is an external Vim plugin which I chose to pack with Yavide to provide auto-completion functionality. But the error you described seems like it had something to do with your local installation of clang-python. I did not see any mention of clang_complete in the error report.

I would try to disable the plugin first and run everything once again and verify if you still get the error or not. You can disable the plugin by appending ~ to its directory name (i.e. clang_complete becomes clang_complete~).

Cheers, Adi

NicolasAubinet commented 7 years ago

I just tried to disable clang_complete and I'm not getting any error, but the completion doesn't work anymore. Renaming the folder to its original name makes completion work again.

Yavide is then clearly reading cindex.py from the yavide installation folder, but the original cindex.py file (after installing yavide) didn't contain the BaseEnumeration definition. Replacing the files from clang_complete in the yavide installation by the clang-python package files fixed the issue because cindex.py in that location defines BaseEnumeration. It's like yavide fetches a clang_complete plugin version that is not compatible with itself.

JBakamovic commented 7 years ago

It could be that the wrong cindex.py is being imported. Haven't seen that kind of issue yet but we shall verify if this is really the case. Can you please do the following:

  1. Disable clang_complete plugin
  2. git checkout concurrent_clang_indexer
  3. go to core/server directory
  4. run PYTHONPATH=../ python -v yavide_server.py

In the given output please check where clang-related stuff is being imported from. You can paste the output here so I can have a look as well.

Thanks, Adi

NicolasAubinet commented 7 years ago

Here's the output of the last command: https://pastebin.com/dz5nx5Td (pasting the text here shows huge text font size, i think it interprets the starting '#', hence the pastebin)

JBakamovic commented 7 years ago

Hm, there doesn't seem to be any mention of libclang related imports (i.e. cindex.py). I believe this is because your default Python interpreter is set to Python3. Both Yavide and libclang bindings support Python2 only. There is no support for Python3 as of now and therefore there is no such package for libclang bindings.

In order to run Yavide properly you should be using Python2 interpreter. I am not sure if Python3 is picked up due to it being a default system configuration and/or (g)vim is actually compiled with Python3 support only. Can you please c/p the output of following commands:

NicolasAubinet commented 7 years ago

Indeed, my default python is python3.

$ python --version Python 3.4.5 $ gvim --version VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jul 30 2017 20:08:08) Included patches: 1-386 Modified by Gentoo-8.0.0386 Compiled by nico@gentoo Huge version with GTK2 GUI. Features included (+) or not (-): +acl +file_in_path +mouse_sgr +tag_old_static +arabic +find_in_path -mouse_sysmouse -tag_any_white +autocmd +float +mouse_urxvt -tcl +balloon_eval +folding +mouse_xterm +termguicolors +browse -footer +multi_byte +terminfo ++builtin_terms +fork() +multi_lang +termresponse +byte_offset +gettext -mzscheme +textobjects +channel -hangul_input -netbeans_intg +timers +cindent +iconv +num64 +title +clientserver +insert_expand +packages +toolbar +clipboard +job +path_extra +user_commands +cmdline_compl +jumplist +perl +vertsplit +cmdline_hist +keymap +persistent_undo +virtualedit +cmdline_info +lambda +postscript +visual +comments +langmap +printer +visualextra +conceal +libcall +profile +viminfo +cryptv +linebreak +python/dyn +vreplace -cscope +lispindent +python3/dyn +wildignore +cursorbind +listcmds +quickfix +wildmenu +cursorshape +localmap +reltime +windows +dialog_con_gui -lua +rightleft +writebackup +diff +menu -ruby +X11 +digraphs +mksession +scrollbind -xfontset +dnd +modify_fname +signs +xim -ebcdic +mouse +smartindent +xpm +emacs_tags +mouseshape +startuptime +xsmp_interact +eval +mouse_dec +statusline +xterm_clipboard +ex_extra -mouse_gpm -sun_workshop -xterm_save +extra_search -mouse_jsbterm +syntax
+farsi +mouse_netterm +tag_binary
system vimrc file: "/etc/vim/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" system gvimrc file: "/etc/vim/gvimrc" user gvimrc file: "$HOME/.gvimrc" 2nd user gvimrc file: "~/.vim/gvimrc" defaults file: "$VIMRUNTIME/defaults.vim" system menu file: "$VIMRUNTIME/menu.vim" fall-back for $VIM: "/usr/share/vim" Compilation: x86_64-pc-linux-gnu-gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/freetype2 -O2 -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: x86_64-pc-linux-gnu-gcc -Wl,-E -Wl,-O1 -L/usr/local/lib -Wl,--as-needed -o gvim -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -lncurses -lnsl -lacl -lattr -ldl -Wl,-E -Wl,-O1 -Wl,--as-needed -L/usr/lib64/perl5/5.24.1/x86_64-linux/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc

JBakamovic commented 7 years ago

Your gvim is compiled with support for both Python2 and Python3 which, according to the official documentation, can be somewhat problematic.

Do you have any easy way on Gentoo to run gvim compiled with Python2 support only? Alternative would be to set your system's default Python interpreter to Python2 but I am not sure if that would break anything else for you ... so I would be more in favor of the first option.

Zitara commented 6 years ago

On Ubuntu, python bindings to Clang with the package: sudo apt-get install python-clang-6.0, should do the trick. Based on stackoverflow.