vim-beancount
vim-beancount copied to clipboard
Autocomplete does not work if beancount is installed via venv
The import of the beancount module uses the system python not the virtual one so fails.
So it looks like to support venv, you'll need to also add https://github.com/jmcantrell/vim-virtualenv to you vim plugin list. I can add a note in the instructions.
Is there any update on this? It would be good if this plugin allows specifying the venv for beancount, especially given that since Ubuntu 23.04, user-level pip no longer works, and it is required to use either venv or apt to install Python packages.
For those who have the same problem, I temporarily solved this by adding
import sys
sys.path.append('<venv path>/lib/python3.11/site-packages')
to the beginning of the Python code in beancount#load_everything inside autoload/beancount.vim.
Did you try also installing the https://github.com/jmcantrell/vim-virtualenv nvim plugin? When I did that, I was able to use an activated venv with my system nvim.
With the path manually added, no other extension is needed, and no venv needs to be activated.
At that point, wouldn't it work to just add the same lines to your init.vim?
I haven't heard about it... It seems to be a NeoVim thing but I'm using GVim, so I'm not sure about it. And I wouldn't want to switch the whole vim to one specific venv just because one plugin need it.
vimrc and init.vim are basically equivalent. I wasn't sure which one you were using, but most settings are the same.
You could use something similar to the autocmd listed here to only apply the settings if you open your beancount file: https://stackoverflow.com/questions/18932012/how-to-load-different-vimrc-file-for-different-working-directory
You could even apply it to *.beancount.
I do know autocmd, but how can I config the Python path in autocmd? And how can I scope it to just the code run by this plugin?
There's only one python interpreter per vim instance. When you modify sys.path, you are modifying it for your entire vim session.
You could put something like
autocmd BufRead,BufNewFile *.beancount python3 import sys; sys.path.append('<venv path>/lib/python3.11/site-packages')
in your .vimrc and it would have the same effect.
Oh, okay, thanks. Good to know.
For record, I added the following to my .vimrc:
autocmd BufRead,BufNewFile *.beancount python3 import sys; sys.path.append('<venv path>/lib/python3.11/site-packages'); import beancount; sys.path.pop()
which seems to work without polluting the import path for the interpreter.