8

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

Je-Hoon Song
  • 301
  • 1
  • 4
  • 7

4 Answers4

7

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.

TobalJackson
  • 139
  • 1
  • 4
1

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/python@3.9/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/python@3.9/bin/python3.9
--   Python path: ['/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/usr/local/Cellar/python@3.9/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/python@3.9/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
qili fang
  • 11
  • 2
0

numpy is kind of a difficult library because it dynamically builds its namespace on import, making it hard for static code analysis tools to know when you're write the code what names should be available. Because the names available in the namespace numpy are only really known at runtime, YCM probably doesn't have any useful suggestions for you.

Daniel Lee
  • 2,030
  • 1
  • 23
  • 29
0

One simple way to fix is activate your python environment, then open vim. For example

(django_mdn) ➜  locallibrary git:(master) ✗ vim

and in the vim run :echo $PATH.

Then you should be able to see that your venv path is at the first like this:

/Users/gwanghyeongim/.virtualenvs/django_mdn/bin:/usr/local/opt/tcl-tk/bin:...

Then see if your python packages are auto-complete.

enter image description here

It worked.

If you want to set a certain site-packages to be auto complete permanently, you need to make a file called .ycm_ extra_conf.py in your project root directory or global_extra_conf.py and set vim configuration if you want to set it globally.

P.S.
By running export PYTHONPATH=/usr/lib/python3.4/site-packages/ in the shell before opening vim didn't work for me. Besides, unless setting PYTHONPATH permanently, which will cause issue, you will have to set export PYTHONPATH everytime you want dependencies to be auto complete.

harryghgim
  • 1,340
  • 4
  • 12
  • 33