1

coc-pyright在 Nvim 中使用并遇到了一些问题。

首先,在 Nvim 中,运行:checkhealth会导致以下错误消息:

## Python 3 provider (optional)
 42   - WARNING: No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
 43   - ERROR: Python provider error:
 44     - ADVICE:
 45       - provider/pythonx: Could not load Python 3:
 46           /home/<project path>/.venv/bin/python3 does not have the "neovim" module. :help provider-python
 47           python3.7 not found in search path or not executable.
 48           python3.6 not found in search path or not executable.
 49           python3.5 not found in search path or not executable.
 50           python3.4 not found in search path or not executable.
 51           python3.3 not found in search path or not executable.
 52           /home/<project path>/.venv/bin/python does not have the "neovim" module. :help provider-python
 53   - INFO: Executable: Not found

这很好,而且很有意义。使用时添加pynvim包(pip install pynvim)将导致以下结果:checkhealth

# Python 3 provider (optional)
 42   - INFO: `g:python3_host_prog` is not set.  Searching for python3 in the environment.
 43   - INFO: Multiple python3 executables found.  Set `g:python3_host_prog` to avoid surprises.
 44   - WARNING: Your virtualenv is not set up optimally.
 45     - ADVICE:
 46       - Create a virtualenv specifically for Neovim and use `g:python3_host_prog`.  This will avoid the need to install the pynvim module in each virtualenv.
 47   - INFO: $VIRTUAL_ENV matches executable
 48   - INFO: Executable: /home/<project path>/.venv/bin/python3
 49   - INFO: Other python executable: /usr/bin/python3
 50   - INFO: Other python executable: /bin/python3
 51   - INFO: Python version: 3.9.5
 52   - INFO: pynvim version: 0.4.3
 53   - OK: Latest pynvim is installed.

这也是有道理的。从全局安装中保存。然而,我遇到的问题是,这需要我同时启用两个单独的虚拟环境。一个用于pynvim单独,另一个用于所有本地项目依赖项,我无法弄清楚我应该如何做到这一点。

如果我启用全局,coc-pyright找不到任何本地模块并且会抛出错误。如果我启用全局,那么 nvim 没有pynvim它需要的。

你应该怎么做?

4

2 回答 2

0

我很抱歉误解了你的帖子。昨晚入睡前,我实际上想过你的意思是不是我以为你的意思。所以,我要道歉。

我想我应该问你是否找到了解决方案?

如果没有,您是否使用任何 pip/venv 包装器,例如“pipenv”或“virtualenvwrapper”(这可能已被弃用)?我问的唯一原因是我知道“pipenv”将允许您在项目的“Pipfile”中实际指定开发部门。那么,您不能将 neovim 和 pyright 作为开发部门添加到您正在进行的任何项目中吗?

如果这不是一个选项,那么 'venv' 有一个命令行参数,允许它访问系统的 python 包。

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.

--system-site-packages可能会有一些帮助。

也许全局安装 neovim 和 pyright,然后在创建项目时,venv,指定此标志。然后指向g:python3_host_prog您为项目新创建的 venv。然后 venv 应该可以访问它需要的所有包,项目中的包以及您的全局“neovim”和“pyright”。

再次,我很抱歉造成误解。那一定是超级屈尊的。

如果您找到了适合您情况的解决方案,请告诉我您做了什么。如果没有,请告诉我我提出的建议是否有效。

谢谢,祝你有美好的一天。

于 2021-07-15T02:02:58.500 回答
0

coc.nvim 和 coc-pyright 不需要pynvim工作,你不需要安装这个模块。

于 2021-09-15T07:43:42.997 回答