Reputation: 71
I just started configuring Vim as an IDE, and the first file I launched into was one that happened to use a Virtual Environment.
In my .vimrc, I added ale as my lint engine, and coc as my autocomplete (intellisense) engine. So I entered, and saw there were errors. I exited vim, and then sourced my virtual environment and entered again, and there were still errors. For some reason, though, they were all at the imports.
I've tried:
let g:ale_virtualenv_dir_names = ['env']
in my .vimrcI setup ale's linters and fixers as the following
" ALE vars
let g:ale_disable_lsp = 1
let g:ale_linters = {
\ 'python': ['flake8'],
\ 'javascript': ['eslint'],
\}
let g:ale_fixers = {
\ 'python': ['black'],
\}
let g:ale_fix_on_save = 1
let g:ale_sign_warning = '-!'
let g:ale_virtualenv_dir_names = ['env']
but it still throws the errors
How do I make it warn using my Virtual Environment?
Upvotes: 3
Views: 2494
Reputation: 873
I am going to assume that you are using Neovim
(or that this solution will also work for Vim
) but YMMV.
==> Run the command :checkhealth provider
in neovim. You want to look for the part about python 3:
## Python 3 provider (optional)
- INFO: Using: g:python3_host_prog = "/home/albaraa/Documents/venv_global/bin/python3"
- INFO: Executable: /home/albaraa/Documents/venv_global/bin/python3
- INFO: Python version: 3.8.5
- INFO: pynvim version: 0.4.2
- OK: Latest pynvim is installed.
============================================================================
If it doesn't say OK
, just follow the prompts given:
let g:python3_host_prog = '/home/albaraa/Documents/venv_global/bin/python3'
pip install neovim pynvim
============================================================================
If it says OK
but it is still not working:
nvimp
and have it do it automatically:alias nvimp="source ~/Documents/venv_global/bin/activate && nvim"
" This should show your virtual environment
:which python
" This should show your virtual environment in the path
:echo $PATH
" This should show your virtual environment is in the path of the neovim command shell (has to be the same as above)
:!echo $PATH
Upvotes: 1
Reputation: 71
I seem to have fixed it. EDIT: I DID NOT FIX IT
In my .vimrc file, I just needed to indent this code block.
let g:ale_fixers = {
\ 'python': ['black'],
\}
It must have made vim and ale confused and threw errors, especially since I put that before my g:virtualenv_dir_names
variable.
It was all to do with my virtual environments, for some reason. If anyone can explain this to me, I'll be thankful.
I needed to rm -dr
my virtual environment I had before, and then remake and reinstall it.
Hope this helps some of you!
Upvotes: 3