griebd / clangHelper

Code completion for c/c++/objc/objc++ in Sublime Text 3 (using libclang)
MIT License
5 stars 0 forks source link

No Module named Clang #1

Open natet opened 8 years ago

natet commented 8 years ago

I am running ST3 build 3095 on Windows 10 with LLVM 3.6.1. When I load up ST3, I get the following error in the console:

reloading plugin clangHelper.codeCompletion Traceback (most recent call last): File "C:\Users\Nathan\AppData\Roaming\Sublime Text 3\Packages\clangHelper\codeCompletion.py", line 15, in from clang.cindex import TranslationUnit ImportError: No module named 'clang'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/init.py", line 90, in import_module File "", line 1584, in _gcd_import File "", line 1565, in _find_and_load File "", line 1532, in _find_and_load_unlocked File "", line 584, in _check_name_wrapper File "", line 1022, in load_module File "", line 1003, in load_module File "", line 560, in module_for_loader_wrapper File "", line 868, in _load_module File "", line 313, in _call_with_frames_removed File "C:\Users\Nathan\AppData\Roaming\Sublime Text 3\Packages\clangHelper\codeCompletion.py", line 19, in if get_libclang_version() == '32': File "C:\Users\Nathan\AppData\Roaming\Sublime Text 3\Packages\clangHelper\tools\libclang_version.py", line 19, in get_libclang_version lib = CDLL(lib_file) File "./ctypes/init.py", line 353, in init OSError: [WinError 193] %1 is not a valid Win32 application

griebd commented 8 years ago

Strange, you got a exception in a try block... Anyway, could you try commenting lines 14 to 32 except by line 28 (your version of LLVM) removing the indentation. something like:

# try:
#     from clang.cindex import TranslationUnit
# # use customized clang python bindings
# except:
#     from clangHelper.tools.libclang_version import get_libclang_version
#     if get_libclang_version() == '32':
#         from clangHelper.clang.cindex32 import TranslationUnit
#     if get_libclang_version() == '33':
#         from clangHelper.clang.cindex33 import TranslationUnit
#     if get_libclang_version() == '34':
#         from clangHelper.clang.cindex34 import TranslationUnit
#     if get_libclang_version() == '35':
#         from clangHelper.clang.cindex35 import TranslationUnit
#     if get_libclang_version() == '36':
from clangHelper.clang.cindex36 import TranslationUnit
#     elif get_libclang_version() == '37':
#         from clangHelper.clang.cindex37 import TranslationUnit
#     if get_libclang_version() == '38':
#         from clangHelper.clang.cindex38 import TranslationUnit

and then report back please. Thanks.

griebd commented 8 years ago

Another thing, your system is 64bits right? ST and LLVM are too? Or is LLVM 32bits for example?

griebd commented 8 years ago

run this on your sublime console and send the results back, please:

import sublime; from sys import version; from platform import platform; from struct import calcsize; print('Sublime:'); print('\tversion:', sublime.version()); print('\tplatform:', sublime.platform()); print('\tarch:', sublime.arch()); print('python:'); print('\tversion:', version); print('\tplatform:', platform()); print('\tarch:', 8 * calcsize("P"))
natet commented 8 years ago

I was using a 32 bit version of clang (the only binaries for 3.6.2 are 32 bit). I've since installed the 64 bit version of 3.7.1. I'll post the results of the other 2 suggestions shortly.

natet commented 8 years ago

Sublime: version: 3095 platform: windows arch: x64

I'm getting closer. After commenting out the lines you suggested, the plugin does load. But, when attempting to do a completion, an error dialog popped up. I can't get it to do it now. What I get in the console is:

Traceback (most recent call last): File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 359, in on_query_completions res = callback.on_query_completions(v, prefix, locations) File "C:\Users\Nathan\AppData\Roaming\Sublime Text 3\Packages\clangHelper\codeCompletion.py", line 163, in on_query_completions cr = self.translation_units[view.id()].codeComplete( KeyError: 16

griebd commented 8 years ago

ok, your first error was because the 32bits LLVM! ctypes, the lib used by python to load LLVM, can't load libs if the architecture mismatch...

but now you have an error in my code, you probably found a bug... if you close this view and reopen and try again the error persist?! if yes, the last line changed? The one that says "KeyError: xx".

griebd commented 8 years ago

Another test would be to right click the view and select 'clangHelper' -> 'Clear all settings on this view', then close and reopen Sublime itself.