Vim Ale linter plugin not working for python code in Windows 10

1.5k views Asked by At

I have latest GVim (v8.2) 64-bit and Miniconda Python 3.8.5 64-bit installed on Windows 10. I am working in the virtual environment da38 and included the following two lines in my $HOME\_vimrc file to point to the correct python interpreter and libraries for this environment:

set pythonthreehome=$HOME\miniconda3\envs\da38
set pythonthreedll=$HOME\miniconda3\envs\da38\python38.dll

Both :echo has('python3') and :echo has('python3_dynamic') return 1. I have installed Vim plugin dense-analysis/ale for python linting, and installed flake8 and black packages in da38 using conda install flake8 black. And I added the following lines in $HOME\_vimrc to configure this plugin:

let g:ale_linters = {'python': ['flake8']}
let g:ale_fixers = {'*': [], 'python': ['black']}
let g:ale_fix_on_save = 1

But the plugin does not show any error on a python file that has many by design: running flake8 test.py on command prompt returns a lot of errors. :ALEInfo repeats these two lines several times:

(executable check - failure) flake8
(finished - exit code 1) 'cmd /s/c "cd /d "C:\Users\Admin\Desktop" && black - < C:\Users\Admin\AppData\Local\Temp\VIBA694.tmp\test.py"'

I am wondering if somehow the correct python path is not being passed to Vim, but cannot figure out what else to do. Any help is much appreciated.

Thanks

UPDATE:

I think I narrowed down the problem. Linter plugin fails when I open test.py with vim from the desktop icon, but works if I first activate the virtual environment with conda activate da38 and then start vim on command prompt. I guess the desktop vim does not see the virtual environment, where the two packages flake8 and black are installed. So I believe the problem is how to add the appropriate python environment to the desktop vim. I should add the vim-conda plugin did not help.

UPDATE #2:

I managed to get vim-conda plugin working with gvim, and now the linter plugin works as expected.

UPDATE #3:

One can avoid using a plugin and instead hard-code the environment path in _vimrc (for windows):

let venv = 'da38'
let mypath = 'C:\Users\Admin\miniconda3\envs\' . venv . ';'
    \      . 'C:\Users\Admin\miniconda3\envs\' . venv . '\Scripts;'
    \      . 'C:\Users\Admin\miniconda3\envs\' . venv . '\Library\bin;'
let $PATH = mypath . $PATH

This code sticks the env path in front of default $PATH.

0

There are 0 answers