Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to get python omnicomplete to work with non-system modules in vim?

The only thing I can get python omnicomplete to work with are system modules. I get nothing for help with modules in my site-packages or modules that I'm currently working on.

like image 216
andrew Avatar asked Oct 13 '08 22:10

andrew


4 Answers

Once I generated ctags for one of my site-packages, it started working for that package -- so I'm guessing that the omnicomplete function depends on ctags for non-sys modules.

EDIT: Not true at all.

Here's the problem -- poor testing on my part -- omnicomplete WAS working for parts of my project, just not most of it.

The issue was that I'm working on a django project, and in order to import django.db, you need to have an environment variable set. Since I couldn't import django.db, any class that inherited from django.db, or any module that imported a class that inherited from django.db wouldn't complete.

like image 167
andrew Avatar answered Sep 23 '22 09:09

andrew


I get completion for my own modules in my PYTHONPATH or site-packages. I'm not sure what version of the pythoncomplete.vim script you're using, but you may want to make sure it's the latest.

EDIT: Here's some examples of what I'm seeing on my system...

This file (mymodule.py), I puth in a directory in PYTHONPATH, and then in site-packages. Both times I was able to get the screenshot below.

myvar = 'test'

def myfunction(foo='test'):
    pass

class MyClass(object):
    pass
like image 37
Jeremy Cantrell Avatar answered Sep 20 '22 09:09

Jeremy Cantrell


Just ran across this on Python reddit tonight: PySmell. Looks like what you're looking for.

PySmell is a python IDE completion helper.

It tries to statically analyze Python source code, without executing it, and generates information about a project’s structure that IDE tools can use.

like image 36
technomalogical Avatar answered Sep 24 '22 09:09

technomalogical


While it's important to note that you must properly set your PYTHONPATH environmental variable, per the the previous answer, there is a notable bug in Vim which prevents omnicompletion from working when an import fails. As of Vim 7.2.79, this bug hasn't been fixed.

like image 27
gotgenes Avatar answered Sep 21 '22 09:09

gotgenes