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

后端 未结 6 1303
余生分开走
余生分开走 2020-12-28 22:26

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

相关标签:
6条回答
  • 2020-12-28 22:32

    Trouble-shooting tip: verify that the module you are trying to omni-complete can be imported by VIM. I had some syntactically correct Python that VIM didn't like:

    :python import {module-name}
     Traceback (most recent call last):
       File "<string>", line 1, in ?
       File "modulename/__init__.py", line 9
         class empty_paranthesis():
                                ^
     SyntaxError: invalid syntax
    

    Case-in-point, removing the parenthesis from my class definition allowed VIM to import the module, and subsequently OmniComplete on that module started to work.

    0 讨论(0)
  • 2020-12-28 22:36

    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.

    0 讨论(0)
  • 2020-12-28 22:41

    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.

    0 讨论(0)
  • 2020-12-28 22:42

    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
    
    0 讨论(0)
  • 2020-12-28 22:50

    I think your after the pydiction script. It lets you add your own stuff and site-packages to omni complete.

    While your at it, add the following to your python.vim file...

     set iskeyword+=.
    

    This will let you auto-complete package functions e.g. if you enter...

     os.path.
    

    and then [CTRL][N], you'll get a list of the functions for os.path.

    0 讨论(0)
  • 2020-12-28 22:53

    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.

    0 讨论(0)
提交回复
热议问题