mfussenegger / nvim-dap-python

An extension for nvim-dap, providing default configurations for python and methods to debug individual test methods or classes.
GNU General Public License v3.0
571 stars 51 forks source link

Is pyenv supported? #69

Closed predmijat closed 2 years ago

predmijat commented 2 years ago

Hi,

I've installed both nvim-dap and nvim-dap-python:

use 'mfussenegger/nvim-dap'
use 'mfussenegger/nvim-dap-python'

debugpy is installed in a separate pyenv - ~/.pyenv/versions/dap/bin/python.

When I open main.py of some Python project while being in a directory where pyenv is recognized/activated (and I can run python main.py and it will all work) and run :lua require'dap'.toggle_breakpoint()<cr> I see the prompt where I choose 1: Launch file, it will fail on importing first library that is not in standard lib (but is installed with pip) - it seems that dap didn't recognized the virtualenv created with pyenv.

Let me know if any other info is needed.

Thanks!

mfussenegger commented 2 years ago

nvim-dap-python only recognizes the VIRTUAL_ENV and CONDA_PREFIX environment variables. You need to activate the virtual env up-front before starting neovim for it to get recognized.

predmijat commented 2 years ago

Considering I have pyrightconfig.json in the project directory which has info on venvPath and venv, solved with this zsh function:

function vv() {
    venv_path=$(rg venvPath pyrightconfig.json | awk '{print $NF}' | tr -d '"')
    venv=$(rg "venv\"" pyrightconfig.json | awk '{print $NF}' | tr -d '"' | tr -d ',')
    export VIRTUAL_ENV="${venv_path}/${venv}"
    nvim
}
mfussenegger commented 2 years ago

Added a way to customize the logic: https://github.com/mfussenegger/nvim-dap-python/pull/70