Black in Vim on Ubuntu 22.04 does not work
I've moved from Ubuntu 21.10 to 22.04 and Black stopped working then. The configuration is fallowing OS: Ubuntu 22.04 Python: Anaconda with Python 3.8 vim version: 8.2.3582 Package manager: Vundle
I did the fallowing to solve the problem as advised in the previous issues (e.g. #2547):
Removed black from .vim/bundle
Removed black from .vim
Installed Black by PluginInstall
Installed Black by typing :Black
The effect is fallowing:
Please wait, one time setup for Black.
Creating a virtualenv in /home/daniel/.vim/black...
(this path can be customized in .vimrc by setting g:black_virtualenv)
Installing Black with pip...
DONE! You are all set, thanks for waiting ✨ 🍰 ✨
Pro-tip: to upgrade Black in the future, use the :BlackUpgrade command and restart Vim.
Error detected while processing /home/daniel/.vim/bundle/black/autoload/black.vim:
line 202:
Traceback (most recent call last):
File "<string>", line 103, in <module>
ModuleNotFoundError: No module named 'black'
Error detected while processing function black#Black:
line 10:
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'Black' is not defined
Press ENTER or type command to continue
Furthermore, I've tried to activate the env created by Black by sourcing ~/.vim/black/bin/activate and checking if Black is installed. If I will do
cd ~/.vim/black/bin
source activate
./python
import black
Everything seems to be okay and black seems to be installed. But in VIM it doesn't work.
Exact same issue here with Debian bookworm (testing) :/
I had the same issue and it seems that the problem comes from how the installation script is detecting python's version. For me this line was returning python 3.8.10 while the version used in the virtualenv was 3.7.12: https://github.com/psf/black/blob/main/autoload/black.vim#L58.
To fix it I just replaced this line with the following: pyver = (3, 7, 12).
It's not a very sustainable fix but I hope it can help.
That worked for me (ver 3.9.12) !
That's strange, because running sys.version_info[:3] inside the black venv returns the right version number: (3, 9, 12)
For anyone else running into this problem, you can get the correct python version by running:
cd ~/.vim/black/bin
./python --version
Closing as a duplicate of #2547