最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - NVIM not refreshing venv after using pip from another shell - Stack Overflow

programmeradmin3浏览0评论

How to "refresh" NVIM venv modules without closing it ?


Currently im struggling with setting up my workspace with NVIM and TMUX. Im opening two panels, one main for nvim, and another one much smaller for console.

I source env/bin/activate both of them and after that im openning NVIM on main panel. My issue is that, whenever i use pip install "x" on lower panel, NVIM doesnt catch that and gives me an errors like "Import "x" could not be resolved". I have to close NVIM and reopen it in order to see changes. Using :e to refresh the file doesnt work. :checkhealth shows that venv is activated with correct PATH.


Worth to mention, im using the same configs on my MacBook and everything works as it should. Using pip on lower panel updates main panel as well.


  • OS: EndeavourOS
  • Terminal: Alacritty + TMUX
  • Python LSP: pyright

Here is an example photo of my problem.
Example.png


Already tried:

  • :e to refresh file
  • :setw synchronize-panes on/off in TMUX
  • :checkhealth shows venv is activated and no errors
  • using built-in NVIM :terminal to activate venv and somehow refresh it (no luck)

How to "refresh" NVIM venv modules without closing it ?


Currently im struggling with setting up my workspace with NVIM and TMUX. Im opening two panels, one main for nvim, and another one much smaller for console.

I source env/bin/activate both of them and after that im openning NVIM on main panel. My issue is that, whenever i use pip install "x" on lower panel, NVIM doesnt catch that and gives me an errors like "Import "x" could not be resolved". I have to close NVIM and reopen it in order to see changes. Using :e to refresh the file doesnt work. :checkhealth shows that venv is activated with correct PATH.


Worth to mention, im using the same configs on my MacBook and everything works as it should. Using pip on lower panel updates main panel as well.


  • OS: EndeavourOS
  • Terminal: Alacritty + TMUX
  • Python LSP: pyright

Here is an example photo of my problem.
Example.png


Already tried:

  • :e to refresh file
  • :setw synchronize-panes on/off in TMUX
  • :checkhealth shows venv is activated and no errors
  • using built-in NVIM :terminal to activate venv and somehow refresh it (no luck)
Share Improve this question edited Feb 17 at 13:39 Tomtei asked Feb 17 at 12:57 TomteiTomtei 13 bronze badges New contributor Tomtei is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1
  • Please do not upload images of code/data/errors. – dimakin Commented Feb 17 at 21:27
Add a comment  | 

1 Answer 1

Reset to default 0

Solution

The problem is LSP.
Using :LspRestart works like a charm in my case.

Can try to setup auto :LspRestart on file save.
Add this to your init.lua or init.vim:

vim.api.nvim_create_autocmd("BufWritePost", {
    pattern = "*.py",
    callback = function()
        vim.cmd("LspRestart")
    end,
})

Or edit your lspconfig pyright settings:

require'lspconfig'.pyright.setup{
    settings = {
        python = {
            analysis = {
                autoSearchPaths = true,
                useLibraryCodeForTypes = true,
                diagnosticMode = "workspace",
            },
        },
    },
}

Reasons why its working on MacOS but not on EndeavourOS

According to ChatGPT:

Inotify vs. FSEvents (Linux vs. macOS)

  • macOS uses FSEvents, which is a more integrated file-watching system.
  • Linux (EndeavourOS) relies on inotify, and sometimes LSP clients don’t trigger reloads as reliably.
  • Pyright might detect venv changes automatically on macOS but not on Linux.
发布评论

评论列表(0)

  1. 暂无评论