palantir/python-language-server

mypy cannot locate local packages

MKrbm opened this issue · 0 comments

MKrbm commented

I am experiencing issues with integrating the Python Language Server (pylsp) in Neovim while using a Conda virtual environment. Despite configuring pylsp and mypy within Neovim, the language server is unable to locate my local Python package, though running mypy directly in the terminal detects the package without any issues.

The error messages displaying is that : Cannot find implementation or library stub for module named "my_lib"

Environment

  • Operating System: OS-X / Ubuntu22.04
  • Neovim Version: v0.10.0 / v0.95
  • Python Language Server (pylsp) Version: Newest version

Configuration

Here is the relevant part of my Neovim configuration for pylsp:

local python_folder = os.getenv("CONDA_PREFIX")
local python_executable = python_folder .. "/bin/python"
local pylsp_executable = python_folder .. "/bin/pylsp"

require("lspconfig").pylsp.setup({
	cmd = { pylsp_executable, "--log-file", "/tmp/pylsp.log" },
	filetypes = { "python" },
	settings = {
		pylsp = {
			configurationSources = { "pycodestyle" },
			formatCommand = { "autopep8" },
			plugins = {
				-- Lint
				pycodestyle = {
					enabled = true,
					maxLineLength = 100, -- default: 79
					aggressive = 2,
				},
				mypy = {
					enabled = true,
					live_mode = true,
					strict = true,
					overrides = { "--python-executable", python_executable },
				},
				-- -- Code refactor
				rope = { enabled = true }, -- This is a python refactoring library (refactor means renaming, extracting functions, ...)

				pydocstyle = { -- n: make sure to install pydocstyle before using it
					enabled = true,
					convention = "google",
				},

				-- Formatting
				black = { enabled = false },
				pyls_isort = { enabled = false },
				yapf = { enabled = false },
				autopep8 = { enabled = true, maxLineLength = 100 }, -- autopep8 is a python formatting library (it fixes the pycodestyle errors)
			},
			log_file = "/tmp/pylsp.log",
		},
	},
})

Expected Behavior

I expect pylsp to correctly locate and interact with my local Python package within the Conda environment, similar to how mypy operates when run directly in the terminal.

Actual Behavior

The language server does not locate my local Python package, causing issues with linting, type checking, and other features provided by pylsp and mypy.

Steps to Reproduce

  1. create virtual env with conda
  2. Install python-lsp and mypy via pip install "python-lsp-server[all]" pylsp-mypy
  3. activate the virtual env and run nvim

Additional Note

  • I have verified that the Conda environment is activated when launching Neovim.
  • I have confirmed that mypy can detect my local packages when it's directly called from terminal by mypy <my_python_file>