Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black in Vim on Ubuntu 22.04 does not work #2876

Closed
DanielWicz opened this issue Feb 9, 2022 · 5 comments
Closed

Black in Vim on Ubuntu 22.04 does not work #2876

DanielWicz opened this issue Feb 9, 2022 · 5 comments
Labels
T: bug Something isn't working

Comments

@DanielWicz
Copy link

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.

@DanielWicz DanielWicz added the T: bug Something isn't working label Feb 9, 2022
@Talw3g
Copy link

Talw3g commented Apr 7, 2022

Exact same issue here with Debian bookworm (testing) :/

@axeng
Copy link

axeng commented Apr 19, 2022

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.

@Talw3g
Copy link

Talw3g commented Apr 19, 2022

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)

@fbunt
Copy link

fbunt commented May 26, 2022

For anyone else running into this problem, you can get the correct python version by running:

cd ~/.vim/black/bin
./python --version

bobwhitelock added a commit to bobwhitelock/dotfiles that referenced this issue Dec 16, 2022
Use `stable` branch as recommended in Black repo + needed to work around
psf/black#2876.
@hauntsaninja
Copy link
Collaborator

Closing as a duplicate of #2547

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants