使用通常的 coc.nvim
+ coc-python
+ jedi
设置 NeoVim 应该使用系统 Python 模块来运行自己的插件但 Jedi 应该能够自动完成安装在事件虚拟环境中的 Python 模块。我该如何设置?
我已经全局安装了 NeoVim 和 pip install
-ed Pylint 和 Jedi。我已经在 NeoVim 中安装了 coc.nvim
和 coc-python
,没有出现任何问题。我在 ~/.vimrc
中有系统 Python 3 路径:
let g:python3_host_prog = '/bin/python'
以及~/coc-settings.json
中的以下内容:
"python.pythonPath": "/bin/python",
"python.jediEnabled": true,
"python.jediPath": "/usr/lib/python3.9/site-packages",
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "/bin/pylint",
"python.linting.flake8Enabled": false
当我创建虚拟环境时,激活它,安装pygame
,然后在其中运行 NeoVim:
➜ python3 -m venv myenv && myenv/bin/activate
➜ pip install pygame
➜ nvim
linter 和 Python 3 提供程序都工作正常。然而,Jedi 会完成本地代码的成员,但不会完成 pygame 的成员,除非我也在虚拟环境之外安装 pygame,即:
➜ deactivate
➜ pip install pygame
➜ myenv/bin/activate
➜ nvim
但是必须安装每个 Python 模块两次,这超出了使用虚拟环境的目的。
最佳答案
找到了。在 coc-settings.json
:
"python.pythonPath": "python",
NeoVim 必须始终使用 /bin/python
但是传递给 Jedi 的路径必须指向虚拟环境中处于事件状态的 Python 3 以及 /bin/python
当它不是时。将 CoC 的 Python 路径设置为 python
让env
照顾好它:
➜ myenv/bin/activate
➜ which python
/home/test/foobar/myenv/bin/python
➜ deactivate
➜ which python
/bin/python
关于pygame - 使 `coc-python` 和 `jedi` 自动完成模块安装在虚拟环境中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66245304/