I'm trying to setup deoplete for Vim in mac os. One requirement for this is to install pynvim
which i did with pip3 install pynvim
Now within Vim, :python3 import pynvim
throws an error ImportError: No module named pynvim
. However, outside Vim, pip3 list
lists the package pynvim
. I don't understand what is going wrong here.
I have collected some information based on which I think i should be able to get some help to prevent this error.
:echo exepath('python3')
returns /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
python3 help('modules')
doen't list the package pynvim
. Interesting thing here is that python3 help('modules')
also shows a warning /usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/setuptools/distutils_patch.py:25: UserWarning: Distutils was imported before Setuptools. This usage is discou raged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/setuptools/distutils_patch.py:25: UserWarning: Distutils was imported before Setuptools. This usage is discou raged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
From this warning, we can see the Vim environment is using python3.8 and not python3.6 which conflicts with what was returned from echo exepath('python3')
pip3 -V
returns pip 20.2.1 from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip (python 3.6)
ls -l /usr/local/bin/python*
shows /usr/local/bin/python -> /usr/local/bin/python3.6
/usr/local/bin/python3 -> ../Cellar/python@3.8/3.8.5/bin/python3
/usr/local/bin/python3-config -> ../Cellar/python@3.8/3.8.5/bin/python3-config
/usr/local/bin/python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
/usr/local/bin/python3.6-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config
/usr/local/bin/python3.6m -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m
/usr/local/bin/python3.6m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config
/usr/local/bin/python3.8 -> ../Cellar/python@3.8/3.8.5/bin/python3.8
/usr/local/bin/python3.8-config -> ../Cellar/python@3.8/3.8.5/bin/python3.8-config
Looks multiple Python version on my mac has messed up things. How do I get rid of this mess and prevent the Vim error?
The underlying issue has to do with the Vim compilation. In my case, my Vim was compiled with Python3 support, so it was using the system python3.8 as the interpreter and all the modules were coming from this system python3.8 path. We can change this by appending to $PYTHONPATH
in .bashrc
, /.zshrc
etc: export PYTHONPATH="/home/user-name/your-python-path/site-packages":$PYTHONPATH
. By doing this, Vim can access all the modules found anywhere in $PYTHONPATH
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.