Neovim配置Python 3 Provider时出现Curl错误求助
问题梳理
使用kickstart.nvim的init.lua配置Neovim时,Python LSP无法正常工作。已完成以下操作:
- 安装
pynvim包 - 在
init.lua中设置vim.g.python3_host_prog指向Python 3.11可执行文件路径
运行:checkhealth provider时,provider-python已识别到Python可执行文件和pynvim包,但出现报错:
WARNING: Could not contact PyPI to get latest version.
ERROR: HTTP request failed: error: curl error with https://pypi.python.org/pypi/pynvim/json: 60
终端单独执行curl https://pypi.python.org/pypi/pynvim/json时,报错:
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
More details here: https://curl.se/docs/sslcerts.htmlcurl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above.
解决步骤
方法1:指定正确的CA证书路径给curl
找到系统中可信的CA证书文件(比如Windows下的curl-ca-bundle.crt,或系统根证书存储文件),在Neovim中配置curl使用该证书:
在init.lua中添加:
vim.g.curl_ca_bundle = "你的CA证书文件绝对路径"
也可先在终端测试指定证书路径的curl命令,确认能正常访问:
curl --cacert /path/to/ca-cert.pem https://pypi.python.org/pypi/pynvim/json
方法2:导入自签名证书到系统信任列表
如果是公司/本地代理插入的自签名证书,将证书添加到系统根证书信任存储:
- Windows:双击证书文件,选择「安装证书」,存储位置选「本地计算机」,再选择「将所有证书放入下列存储」,浏览到「受信任的根证书颁发机构」完成导入。
- Linux:将证书复制到
/usr/local/share/ca-certificates/目录,运行sudo update-ca-certificates。 - macOS:双击证书文件,在钥匙串访问中找到该证书,右键选择「显示简介」,将「信任」设置为「始终信任」。
方法3:临时绕过SSL验证(不推荐)
仅用于应急测试,不建议长期使用:
在Neovim中设置curl跳过SSL验证:
vim.g.curl_ssl_verify = 0
或终端执行:
curl -k https://pypi.python.org/pypi/pynvim/json
额外检查Python LSP配置
若解决证书问题后Python LSP仍无法工作,检查kickstart.nvim中Python LSP(如pyright)的配置:
确认pyright已通过:LspInstall pyright安装,并用:LspInfo查看LSP服务是否正常启动。
内容的提问来源于stack exchange,提问作者user865906

