Skip to content
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

mypy cannot locate local packages #970

Open
MKrbm opened this issue Jan 8, 2024 · 0 comments
Open

mypy cannot locate local packages #970

MKrbm opened this issue Jan 8, 2024 · 0 comments

Comments

@MKrbm
Copy link

MKrbm commented Jan 8, 2024

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant