linux-cultist / venv-selector.nvim

Allows selection of python virtual environment from within neovim
MIT License
379 stars 40 forks source link

Imports are not getting resolved. #89

Closed BSiddharth closed 6 months ago

BSiddharth commented 6 months ago

image

At the bottom we can see the venv has been activated.

But at the top django is still not getting resolved.

Also In the floating terminal we can see the venv used is same as the one that has been activated and that django has been installed in this venv.

I am using pyright. And my lazy setup is like this

image

mennohofste commented 6 months ago

Can you confirm the correct python path and venv are selected when you run the following?

require('venv-selector').current_python_path

and

require('venv-selector').current_venv
BSiddharth commented 6 months ago

@mennohofste I get nil for both:lua print(require('venv-selector').current_python_path) and :lua print(require('venv-selector').current_venv)

BSiddharth commented 6 months ago

@mennohofste I was looking around the code checking why I am getting nil on require('venv-selector').current_python_path. But there is no .current_python_path. Did you meant require('venv-selector.venv').current_python_path) or maybe require('venv-selector').get_active_path(). If yes then it is the expected path to my venv and not nil as stated in my last comment

silentnights commented 6 months ago

I have the same issue here using poetry as a venv manager. After selecting a venv, pyright can't find the imports, but nvim-dap-python executes the code properly.

printing the two variables require('venv-selector.venv').current_python_path) and require('venv-selector').get_active_path() shows the proper virtual environment.

silentnights commented 6 months ago

After digging around, I think the problem is coming from mypy and not pyright. I am not sure if I am doing something wrong here, but I am using https://github.com/dreamsofcode-io/neovim-python as my base configuration and replacing null-ls with none-ls instead.

The none-ls config enables mypy diagnostics. Disabling it removes the missing import issue from popping up.

What is interesting is that when I removed mypy from the none-ls opts, I get the proper linting behavior:

For me, it is not clear if mypy diagnostic is required at all.

BSiddharth commented 6 months ago

@silentnights Oh why did I not think about that. Pyright knows the correct env but mypy has no idea. I had disabled diagnostics for pyright and was using just mypy bcz i did not like seeing same diagnostics from pyright and mypy.

I have removed mypy for now. I don't really utilize its that much. And now I can also work without venv selector since I spawn the poetry shell before opening nvim. Venv selector would have been useful if I was switching between multiple venv I guess.

Completely skipped my mind haha thanks. I will close this issue.