Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouCompleteMe/Python can complete for built-in libs, but not site-packages

I just installed ycm, everything looks good, but I found small problem. The problem is as following:

import os    # os is built-in library
os.          # ycm helps to complete members of the class.
import numpy # numpy is not built-in library, where its location is site-packages. 
numpy.       # nothing happened. ycm shows 'pattern not found' message.

I think, this would be a simple problem. But I could not find the solution yet. I think, there is some configuration file in which I can define 'search path' for my project.

It would be grateful if I can find a way to solve it.

Best,

Je-Hoon Song

like image 590
Je-Hoon Song Avatar asked Jun 22 '14 10:06

Je-Hoon Song


2 Answers

I had the same issue with module 'mpmath' and fixed it in the following manner: First I retrieved the path where the module was located:

%python3
>>>import mpmath
>>>print(mpmath.__file__)
/usr/lib/python3.4/site-packages/mpmath/__init__.py

Here I found the path of all my "installed" python3 packages to be:

/usr/lib/python3.4/site-packages/

I then simply added to my PYTHONPATH environment variable this path:

%export PYTHONPATH=/usr/lib/python3.4/site-packages/

Then when I used vim sample.py typing import mpmath and following it up with mpmath. YCM showed me all the autocompletions for the mpmath module.

Hope this helps.

like image 193
TobalJackson Avatar answered Sep 18 '22 13:09

TobalJackson


I use anaconda python to be my python interpreter in ycm to solve this. First I modified my vimrc according to full pythong setting in vim. Then I change g:ycm_python_interpreter_path by

let g:ycm_python_interpreter_path = '/usr/local/anaconda3/bin/python3.8'

In this way I didn't change the system environment variables.

Addtional Info 1: I think the main problem is that, my Python interpreter for YCM is my system python (/usr/local/opt/[email protected]/bin/python3.9 ), which only has limited locally built libraries. So using the libraries comes with anaconda (/usr/local/anaconda3/bin/python3.8 ) can solve.

Additional Info 2: By reading :YcmDebugInfo, the main different after edited g:ycm_python_interpreter_path is that:

-- Python completer debug information:
--   Python interpreter: /usr/local/opt/[email protected]/bin/python3.9
--   Python path: ['/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/site-packages']
--   Python version: 3.9.6

change to

-- Python completer debug information:
--   Python interpreter: /usr/local/anaconda3/bin/python3.8
--   Python path: ['/usr/local/anaconda3/lib/python38.zip', '/usr/local/anaconda3/lib/python3.8', '/usr/local/anaconda3/lib/python3.8/lib-dynload', '/usr/local/anaconda3/lib/python3.8/site-packages', '/usr/local/anaconda3/lib/python3.8/site-packages/aeosa', '/usr/local/anaconda3/lib/python3.8/site-packages/locket-0.2.1-py3.8.egg']
--   Python version: 3.8.8

Additional Info 3: about how to read list of locally installed pyton modules use https://stackoverflow.com/a/740018/11226687 e.g. in my case

$ /usr/local/opt/[email protected]/bin/python3.9
>>> help('modules')
# only return limitted modules
$ /usr/local/anaconda3/bin/python3
>>> help('modules')
# list out all the modules included in Anaconda, including numpy/matplotlib/scipy ect
like image 38
qili fang Avatar answered Sep 21 '22 13:09

qili fang