nvim-dap-python
nvim-dap-python copied to clipboard
Doesn't pick up conda environemt
Hi!
I am trying to use this with miniconda, however it doesn't pick up the environment.
This is the setup that I have:
require('dap-python').setup('/home/xxx/miniconda3/bin/python')
require("dapui").setup()
require("nvim-dap-virtual-text").setup()
vim.fn.sign_define('DapStopped', {
text='▶', texthl='WarningMsg',linehl='DapUIBreakpointsCurrentLine', numhl='ModeMsg'})
vim.fn.sign_define('DapBreakpoint', {
text='●', texthl='ErrorMsg', linehl='', numhl=''})
vim.fn.sign_define('DapBreakpointCondition', {
text='⊕', texthl='ErrorMsg', linehl='', numhl=''})
vim.fn.sign_define('DapLogPoint', {
text='!!', texthl='ErrorMsg', linehl='', numhl=''})
vim.fn.sign_define('DapBreakpointRejected', {
text='⨷', texthl='ErrorMsg', linehl='', numhl=''})
I have debugpy installed in this environment. So, I create a file example.py, add two lines:
import numpy as np
print("example") # <-- add breakpoint here
It doesn't work (as was expected), as the base environment doesn't have numpy installed.
Then I go to a project /home/xxx/Projects/project-1. This project has a conda environment project-1. I activate the environemnt.
I run the debugger and I get the same error -- numpy not found.
If I change the line in the config require('dap-python').setup('/home/xxx/miniconda3/bin/python')
to require('dap-python').setup('/home/xxx/miniconda3/envs/project-1/bin/python')
and install debugpy in this environment, then of course debugging does work - it finds the numpy installation.
However, my question is - shouldn't the debugger pick up the new environment by default? Why do I need to change the python interpreter path in the config?
Many thanks and please forgive my noob question
nvim-dap currently only recognizes the VIRTUAL_ENV
environment variable out of the box.
It doesn't recognize conda environments.
Why do I need to change the python interpreter path in the config?
You don't necessarily need to do that, you could also add python
or pythonPath
properties to your configuration, or you could set the VIRTUAL_ENV
environment variable.
I have run into this as well. Quite noobie on this, but here goes...
require('dap-python').setup(<path>)
runs when nvim opens. But is there a way to 'reset' the path when the debugger is initiated? Looking here, the env is detected:
local venv = os.getenv("VIRTUAL_ENV")
command = vim.fn.getcwd() .. string.format("%s/bin/python",venv)
and the current conda environment is at CONDA_PREFIX
. So is it as simple as just checking if VIRTUAL_ENV
is empty, then checking if CONDA_PREFIX
is empty, and otherwise using the default path, on debugger initialization?
@ccaprani You can hack around by setting VIRTUAL_ENV
variable like mentioned.
steps
- Activate your conda env and run
conda env config vars set VIRTUAL_ENV=$(which python) && conda deactivate
- re-activate your conda env. now it should work.
Personally i found using conda with tmux+NeoVim not plesant. so i switched to python built-in venv.
For anyone else still experiencing this issue, run the following in your conda environment(s):
conda env config vars set VIRTUAL_ENV=\$CONDA_PREFIX && conda deactivate