Skip to content

Failed to load hook pylsp_lint: [Errno 2] No such file or directory: '' #369

Closed

Description

@Ultimator14

When opening a standalone file (that does not have a project root), pylint crashes and no diagnostics are displayed.

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/pylsp/config/config.py", line 33, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 327, in traced_hookexec
    return outcome.get_result()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 33, in from_call
    result = func()
             ^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 324, in <lambda>
    lambda: oldcall(hook_name, hook_impls, kwargs, firstresult)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pylsp/plugins/pylint_lint.py", line 220, in pylsp_lint
    return PylintLinter.lint(document, is_saved, flags=flags)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pylsp/plugins/pylint_lint.py", line 98, in lint
    with Popen(cmd, stdout=PIPE, stderr=PIPE,
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1917, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ''

The failing code is

with Popen(cmd, stdout=PIPE, stderr=PIPE,
                   cwd=document._workspace.root_path, universal_newlines=True) as process:

with document._workspace.root_path being an empty string. The problem is that the Popen cwd argument is always set, regardless of the root_path. To make this work, the value should be set to the directory of the file if no root path exists.
This works for me

if not (cwd := document._workspace.root_path):
    cwd = os.path.dirname(__file__)

with Popen(cmd, stdout=PIPE, stderr=PIPE,
                   cwd=cwd, universal_newlines=True) as process:

Pylsp version: 1.7.2
Editor: Neovim: 0.8.3

Activity

  1. mxkrsv commented on Apr 23, 2023

    @mxkrsv

    Same here, neovim log:

    [ERROR][2023-04-23 14:41:10] .../vim/lsp/rpc.lua:734	"rpc"	"pylsp"	"stderr"	"2023-04-23 14:41:10,325 MSK - WARNING - pylsp.config.config - Failed to load hook pylsp_lint: [Errno 2] No such file or directory: ''\nTraceback (most recent call last):\n  File \"/nix/store/mdmff1mbn88k2nqkjnwk64fzn6ij2672-python3.10-python-lsp-server-1.7.2/lib/python3.10/site-packages/pylsp/config/config.py\", line 33, in _hookexec\n    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_manager.py\", line 327, in traced_hookexec\n    return outcome.get_result()\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_result.py\", line 60, in get_result\n    raise ex[1].with_traceback(ex[2])\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_result.py\", line 33, in from_call\n    result = func()\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_manager.py\", line 324, in <lambda>\n    lambda: oldcall(hook_name, hook_impls, kwargs, firstresult)\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_callers.py\", line 60, in _multicall\n    return outcome.get_result()\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_result.py\", line 60, in get_result\n    raise ex[1].with_traceback(ex[2])\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_callers.py\", line 39, in _multicall\n    res = hook_impl.function(*args)\n  File \"/nix/store/mdmff1mbn88k2nqkjnwk64fzn6ij2672-python3.10-python-lsp-server-1.7.2/lib/python3.10/site-packages/pylsp/plugins/pylint_lint.py\", line 220, in pylsp_lint\n    return PylintLinter.lint(document, is_saved, flags=flags)\n  File \"/nix/store/mdmff1mbn88k2nqkjnwk64fzn6ij2672-python3.10-python-lsp-server-1.7.2/lib/python3.10/site-packages/pylsp/plugins/pylint_lint.py\", line 98, in lint\n    with Popen(cmd, stdout=PIPE, stderr=PIPE,\n  File \"/nix/store/fdqpyj613dr0v1l1lrzqhzay7sk4xg87-python3-3.10.10/lib/python3.10/subprocess.py\", line 971, in __init__\n    self._execute_child(args, executable, preexec_fn, close_fds,\n  File \"/nix/store/fdqpyj613dr0v1l1lrzqhzay7sk4xg87-python3-3.10.10/lib/python3.10/subprocess.py\", line 1847, in _execute_child\n    raise child_exception_type(errno_num, err_msg, err_filename)\nFileNotFoundError: [Errno 2] No such file or directory: ''\n"
    
  2. ccordoba12 commented on Apr 24, 2023

    @ccordoba12
    Member

    Hey @Ultimator14, thanks for reporting this problem and finding a solution for it! Would you like to submit a pull request with your fix?

  3. added this to the v1.7.3 milestone on Apr 24, 2023
  4. added a commit that references this issue on May 11, 2026
  5. added a commit that references this issue on May 14, 2026
  6. added a commit that references this issue on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions