-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Cannot find implementation or library stub for module named" error has been persisten with neovim's lspconfig. #84
Comments
You likely want a true somewhere in your overrides. (I really should document that better …) I guess this could be an issue with having multiple environments. |
I'm having this problem as well. I'm using mypy plugin from mason's virtual environment (not the project virtual environment) The project virual environment is activated, but I don't know how the two environments work together. |
@Susensio You might have to set |
I have the same issue. I set the python-executable to Even if i pass a non-existent python-executable, i.e. overrides = {--python-executable, 'random', true} I get not errors in the Logs, and mypy keeps giving me the same |
@adamingas Does it work on the command line for you? |
Running mypy from the environment it's installed in (a conda environment) with the correct python executable given as argument (the python binary in my project's venv), works as expected. I also tried importing mypy and running it from an ipython shell, and that works as well. |
The pylsp-mypy log should be part of the lsp-server log. Could you please provide that? |
Cleared logs, opened a python file, cleared sensitive information, and pasted the logs:
My lsp config: local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
vim.lsp.set_log_level("debug")
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap=true, silent=true, buffer=bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>fr', vim.lsp.buf.format, bufopts)
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, bufopts)
end
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
local lspconfig = require('lspconfig')
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local servers = {
-- 'pyright',
'pylsp'
}
-- for _, lsp in ipairs(servers) do
-- lspconfig[lsp].setup {
-- }
-- end
mypy_config = {enabled = true}
if vim.env.VIRTUAL_ENV ~=nil then
mypy_config = {enabled = true, overrides= {true, "--python-executable",vim.env.VIRTUAL_ENV .. "/bin/python"}}
end
lspconfig['pylsp'].setup{
cmd = {string.sub(vim.g.python3_host_prog,0,-7) .. 'pylsp'}, -- {"/Users/u1078811/mambaforge/envs/nvim/bin/pylsp"},
on_attach = on_attach,
capabilities = capabilities,
pylsp = {
plugins = {
ruff = {
enabled = true,
unsafe_fixes = true,
formatEnabled = true,
format = {'I' , 'F'},
line_length = 90
},
jedi = {
auto_import_modules = {'pandas','numpy'}
},
pylsp_mypy = mypy_config
}
}
}
-- lspconfig['ltex'].setup{
-- filetypes = { "bib", "gitcommit", "markdown", "org", "plaintex", "rst", "rnoweb", "tex", "pandoc" ,"vimwiki"}
-- }
lspconfig["jsonls"].setup{
filetypes = { "json" },
cmd = {'vscode-json-languageserver', '--stdio'},
} |
Just realised my pylsp config was wrong. The pylsp nested table should be under a settings key. lspconfig['pylsp'].setup{
cmd = {string.sub(vim.g.python3_host_prog,0,-7) .. 'pylsp'}, -- {"/Users/u1078811/mambaforge/envs/nvim/bin/pylsp"},
on_attach = on_attach,
capabilities = capabilities,
pylsp = {
plugins = {
ruff = {
enabled = true,
unsafe_fixes = true,
formatEnabled = true,
format = {'I' , 'F'},
line_length = 90
},
jedi = {
auto_import_modules = {'pandas','numpy'}
},
pylsp_mypy = mypy_config
}
}
} to lspconfig['pylsp'].setup{
cmd = {string.sub(vim.g.python3_host_prog,0,-7) .. 'pylsp'}, -- {"/Users/u1078811/mambaforge/envs/nvim/bin/pylsp"},
on_attach = on_attach,
capabilities = capabilities,
settings = {
pylsp = {
plugins = {
ruff = {
enabled = true,
unsafe_fixes = true,
formatEnabled = true,
format = {'I' , 'F'},
line_length = 90
},
jedi = {
auto_import_modules = {'pandas','numpy'}
},
pylsp_mypy = mypy_config
}
}
}
} And using this mypy config mypy_config = {enabled = true}
if vim.env.VIRTUAL_ENV ~=nil then
mypy_config = {enabled = true, overrides= {true, "--python-executable",vim.env.VIRTUAL_ENV .. "/bin/python"}}
end Works with the current active venv's python/packages. With that i consider the issue solved for me. |
Error message
Cannot find implementation or library stub for module named "module name"
always appears whenever I define custom modules.The minimum example project structure is like below where
my_add
function is defined infoo.py
and themain.py
tries to import the function.lib1/
├── init.py
└── foo.py
main.py
When I run mypy from command line, I can get the expected result
The configuration of the pylsp in my neovim is like
I'been suffering from this bug? for half a year. Is there any solution? Thank you !
The text was updated successfully, but these errors were encountered: