I read the README of the jedi-vim. https://github.com/davidhalter/jedi
There are screenshots of omni completing with a non-standard library (Django).
I installed django by pip and tried exact same code to test omni completion of Django, but it doesn't work.
Omni completion (^O^N^P) Pattern not found.
Standard library's omni completion is working perfect.
I'm usually using some non-standard library so I want to use omni completion with those libraries.
Should I do some configuration to use omni completion with non-standard libraries?
Most third libraries should work out of the box, Django isn't so nice with autocompletion, you need to have in your environment the variable DJANGO_SETTINGS
set, otherwise most imports will raise an improperly configured exception and the autocompletion will not work.
You can set this variable in you virtualenv, or with a alias in your shell, or using something like this in your .vimrc
:
function FindDjangoSettings()
if strlen($VIRTUAL_ENV) && has('python')
let output = system("find $VIRTUAL_ENV \\( -wholename '*/lib/*' -or -wholename '*/install/' \\) -or \\( -name 'settings.py' -print0 \\) | tr '\n' ' '")
let outarray= split(output, '[\/]\+')
let module = outarray[-2] . '.' . 'settings'
let syspath = system("python -c 'import sys; print sys.path' | tr '\n' ' ' ")
" let curpath = '/' . join(outarray[:-2], '/')
execute 'python import sys, os'
" execute 'python sys.path.append("' . curpath . '")'
" execute 'python sys.path.append("' . syspath . '")'
execute 'python sys.path = ' . syspath
execute 'python os.environ.setdefault("DJANGO_SETTINGS_MODULE", "' . module . '")'
endif
endfunction
autocmd FileType python call FindDjangoSettings()
This assumes that you are using virtualenv
for your projects, and might bother you if you are using a virtualenv for something that is not django.
I also recommend you to have a look in you complete me plugin, its an awesome complete plugin, it is not a replacement for jedi, in fact, it has jedi as a dependency for python completion.
You can try this: sys.path.append(/path/to/lib)
I use SUMO/TraCI as a non-standard lib.
In python code I have added sys.path.append("/path/to/SUMO/tools/")
before using traci methods and then completion in Vim works perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With