简体   繁体   English

Python3 未列出 Vim 8 中安装的 pip 模块

[英]Python3 not listing the pip installed modules in Vim 8

I'm trying to setup deoplete for Vim in mac os.我正在尝试在 mac os 中为 Vim 设置 deoplete。 One requirement for this is to install pynvim which i did with pip3 install pynvim对此的一个要求是安装我用pip3 install pynvim pynvim

Now within Vim, :python3 import pynvim throws an error ImportError: No module named pynvim .现在在 Vim 中, :python3 import pynvim会抛出错误ImportError: No module named pynvim However, outside Vim, pip3 list lists the package pynvim .但是,在 Vim 之外, pip3 list列出了 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.我已经收集了一些信息,我认为我应该能够根据这些信息获得一些帮助来防止这个错误。

  • From Vim, :echo exepath('python3') returns /Library/Frameworks/Python.framework/Versions/3.6/bin/python3从 Vim 中, :echo exepath('python3')返回/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
  • From Vim, python3 help('modules') doen't list the package pynvim .从 Vim 开始, python3 help('modules')没有列出 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.这里有趣的是python3 help('modules')还显示警告/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')从这个警告中,我们可以看到 Vim 环境正在使用 python3.8 而不是 python3.6,这与从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) pip3 -V 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 ls -l /usr/local/bin/python*显示
/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.看起来我的 Mac 上的多个 Python 版本搞砸了。 How do I get rid of this mess and prevent the Vim error?如何摆脱这种混乱并防止 Vim 错误?

The underlying issue has to do with the Vim compilation.根本问题与 Vim 编译有关。 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.在我的例子中,我的 Vim 是在 Python3 支持下编译的,所以它使用系统 python3.8 作为解释器,所有模块都来自这个系统 python3.8 路径。 We can change this by appending to $PYTHONPATH in .bashrc , /.zshrc etc: export PYTHONPATH="/home/user-name/your-python-path/site-packages":$PYTHONPATH .我们可以通过在.bashrc/.zshrc等中附加到$PYTHONPATH来更改它: export PYTHONPATH="/home/user-name/your-python-path/site-packages":$PYTHONPATH By doing this, Vim can access all the modules found anywhere in $PYTHONPATH .通过这样做,Vim 可以访问$PYTHONPATH中任何位置的所有模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM