Closed SomeoneSerge closed 3 years ago
Upd: found that python executable is exposed to nvim, as it is supposed to, through g:python3_host_prog
and not PATH
:
:echo g:python3_host_prog
/nix/store/gsb3ahrqpd99i4frbrsdb2br3chi88gl-neovim-0.4.4/bin/nvim-python3
Apparently the solution would be to allow to populate the coc-settings.json
with python.linting.pylintPath
, etc.
I temporarily resorted to the following hack and it kind of works:
# home.nix
xdg.configFile."nvim/coc-settings.json".text = ''
{
"python.linting.pylintPath": "nix-shell -p 'python3.withPackages(ps: [ps.pylint])' --run 'python -m pylint'"
}
'';
The UX I'd expect is that adding coc-python
to neovim plugins would automatically include pylint
, black
, isort
, etc in the closure and that neovim would be exposed to their executables. I could work on that some time later, but I wouldn't know how to approach the problem. I find nixpkgs somewhat overwhelming
I'm just a NixOS newbie, so I might be doing something very wrong here, but for black
and flake8
the following works for me:
# configuration.nix
home-manager = {
# ..
programs = {
neovim = {
extraPackages = with pkgs; [
(python3.withPackages (ps: with ps; [
black
flake8
]))
];
This seems to install black
and flake8
and expose them in the PATH to the Neovim process, so you would not need your xdg.configFile
hack.
I still have not managed to get jedi
working, though: Python complains about module jedi
not being found, even when I add it to the extraPython3Packages
option.
@carletes, modules from extraPython3Packages
ends up available to nvim-python3
. Try to make sure it's the one you invoke (e.g., as nvim-python3 -m jedi
).
@carletes for myself, I hotfixed jedi by explicitly providing path to its site-packages
: https://github.com/newkozlukov/dotfiles/blob/7058ff268c6d802621135831b5271ecc781a7c2c/home/program/neovim/coc.nix#L5 (here pylinters
comes from https://github.com/newkozlukov/dotfiles/blob/7058ff268c6d802621135831b5271ecc781a7c2c/overlays/pylinters.nix#L33 but probably most of this terrible messy hack is unnecessary; I just don't have time to clean it up)
I didn't check @t184256's solution now, but when I just opened this issue, extraPython3Packages
didn't work (at least for me, at least with jedi)
Also, didn't know about nvim-python3
, will look into where's it constructed and how - later
Thanks
Try to make sure it's the one you invoke (e.g., as nvim-python3 -m jedi).
@t184256: Thanks for the hint! Yes, I did a /nix/store/<blahblah>/nvim-python3 -m jedi
in another terminal and it worked (as in nvim-python3
as able to locate the jedi
module).
All I had to do then was to set python.pythonPath
to pnvim-python3
in my coc-settings.json
and then everything works.
For black
and flake8
I made them accessible to nvim
's PATH by adding them to
extraPackages`, and that seems to do the trick.
To sum up: The following configuration (I use home-manager
driven from /etc/nixos/configuration.nix
) works for me:
# configuration.nix
{
home-manager = {
programs = {
neovim = {
enable =true;
withPython3 = true;
plugins = with pkgs.vimPlugins; [
coc-nvim
coc-python
];
extraPackages = with pkgs; [
(python3.withPackages (ps: with ps; [
black
flake8
]))
];
extraPython3Packages = (ps: with ps; [
jedi
]);
};
};
};
xdg.configFile."nvim/coc-settings.json".text = builtins.readFile ./my-coc-settings.json;
}
And here are the relevant bits of my-coc-settings.json
:
{
"python.formatting.provider": "black",
"python.jediEnabled": true,
"python.linting.flake8Enabled": true,
"python.pythonPath": "nvim-python3"
}
I marked this as stale due to inactivity. → More info
works for me let g:python3_host_prog='/usr/bin/python3'
(add to your vimrc)
@HT-Moh I'm almost sure that just withPython3
started working since some commit a rather long time ago - the issue can be probably closed already
Also, I recently switched to neovim-nightly
with nvim-lspconfig
instead of coc
and I feel happy
I know this is outdated but a search dropped me here and I wanted to document the fix that worked for me for those in the future. (NixOS newbie as well)
Turns out in 2022 coc-python
is archived and you should be using coc-pyright
. I didn't have to play with extraPython3Packages
or extraPackages
at all. Once I replaced coc-python
with coc-pyright
all was good.
Describe the bug
The
neovim
withvimPlugins."coc-python"
in eitherconfigure.packages.myVimPackages.start
orplug.plugins
doesn't bring python into scope, resulting inpylint
To Reproduce Steps to reproduce the behavior:
home-manager
withneovim.plugins = [coc-nvim coc-python]
shell.nix
withnix-shell
in the directory withshell.nix
(orhome-manager switch
)nvim example.py
:! which python
:! which node
Expected behavior
:!
, but regardless)Observed behaviour
pylint
. An error reporting "No Python interpreter"Additional context Add any other context about the problem here.
Notify maintainers
@vcunat (found in
vim-plugins/overrides.nix
)Metadata Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.Maintainer information: