Jedi Vim Python subclasses are not detected on TAB-completion

时间秒杀一切 提交于 2019-11-28 06:00:27

问题


The issue is on Arch (1) & Debian Jessie (2) where:

1.

> uname -r
4.0.5-1-ARCH
> echo $PYTHONPATH
/usr/lib/python2.7/
  1. Debian Jessie is without the PYTHONPATH set.

My vim is compiled with python.

:python import sys; print(sys.version)
2.7.10 (default, May 26 2015, 04:16:29)
[GCC 5.1.0]

I tried the following Arch Linux packages:

> pacman -S python2-jedi vim-jedi

completion works on classes but not on the subclasses.

import os          # os is built-in library.
os.                # ycm does not complete members of this class.

I removed them and downloaded the git package.

> cd ~/.vim/bundle/jedi-vim/jedi/test/ && ./run.py
Summary: (0 fails of 962 tests) in 18.819s

> cd ../ && ./setup build && ./setup install

And again, completion works on classes but not on the subclasses.

My previous question that sent me to jedi-vim from Vim YouCompleteMe Python subclasses are not detected on TAB-completion in Arch Linux


回答1:


I just realized that I did an error due to my incomprehension. I was trying to import the following way:

Which was natural when I used ipython with tab completion like this:

That is a wrong way to import a module in a python script. This is the right way:

Finally, the Jedi-Vim plug-in works perfectly. In case of uncertainty related to unavailable imports you can verify your imports with:

:python import sys; print(sys.path)

And then add the missing directories during the run time to test if their absence was causing the issue.

:python import sys; sys.path.append("/path/to/dir")

In my case the os.py was located at /usr/lib/python2.7/.

I hope this clarifies this for the future Jedi-Vim users.




回答2:


Old question, but I've found an alternative to amending sys.path if you are using virtual environments.

You can instead create a .pth (https://docs.python.org/2/library/site.html) file in your <virtualenv>/lib/<python>/site-packages folder that points to the root of your source e.g. if my source was in /user/123/python-proj/source folder and my virtual env was in the /user/123/python-proj/venv folder

echo '/user/123/python-proj/source > /user/123/python-proj/venv/lib/python3.5/site-packages/my-source.pth'

Make sure you activate the virtual env first, then launch vim and jedi should be able to find your code.



来源:https://stackoverflow.com/questions/31233669/jedi-vim-python-subclasses-are-not-detected-on-tab-completion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!