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

Plugin can't find black python module #2547

Open
scottwn opened this issue Oct 19, 2021 · 8 comments · May be fixed by #4245
Open

Plugin can't find black python module #2547

scottwn opened this issue Oct 19, 2021 · 8 comments · May be fixed by #4245
Labels
T: bug Something isn't working

Comments

@scottwn
Copy link

scottwn commented Oct 19, 2021

Describe the bug
I have installed Black using vim-plug. Installation is successful and I can update the plugin no problem. However when I run black inside Vim I get the following error

Error detected while processing /Users/scott/.vim/plugged/black/autoload/black.vim:
line  195:
Traceback (most recent call last):
  File "<string>", line 97, 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

To Reproduce
Install Black via vim-plug
Run black in Vim

Expected behavior

I expect Black to run successfully

Environment (please complete the following information):

  • Version: main
  • OS and Python version: Mac OS 11.6 Big Sur, Python 3.10

Does this bug also happen on main?
Yes, I've forced vim-plug to use main and we can see that in the PlugUpdate output.

  1 Updated. Elapsed time: 3.993817 sec.
  2 [============]
  3
  4 - Finishing ... Done!
  5 - neoformat: Already up to date.
  6 - MatchTagAlways: Already up to date.
  7 - vim-es2015-snippets: Already up to date.
  8 - vim-react-snippets: Already up to date.
  9 - vim-jsx: Already up to date.
 10 - vim-prettier: Already up to date.
 11 - tsuquyomi: Already up to date.
 12 - typescript-vim: Already up to date.
 13 - vim-snippets: Already up to date.
 14 - ultisnips: Already up to date.
 15 - black: Your branch is up to date with 'origin/main'.
 16 - vim-javascript: Already up to date.

Additional context

I am using Vim inside Fish shell.

@scottwn scottwn added the T: bug Something isn't working label Oct 19, 2021
@scottwn
Copy link
Author

scottwn commented Oct 19, 2021

After clearing out the existing installation of Black and reinstalling with vim-plug using 'branch': 'stable' as indicated in the doc, I am getting a regex error.

Please wait, one time setup for Black.WARNING: You are using pip version 21.2.4; however, version 21.3 is available.
               You should consider upgrading via the '/Users/scott/.vim/black/bin/python3 -m pip install --upgrade pip' command.

Creating a virtualenv in /Users/scott/.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 /Users/scott/.vim/plugged/black/autoload/black.vim:
line  161:
Traceback (most recent call last):
  File "<string>", line 97, in <module>
  File "/Users/scott/.vim/black/lib/python3.9/site-packages/black/__init__.py", line 13, in <module>
    import regex as re
  File "/Users/scott/.vim/black/lib/python3.9/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/Users/scott/.vim/black/lib/python3.9/site-packages/regex/regex.py", line 419, in <module>
    import regex._regex_core as _regex_core
  File "/Users/scott/.vim/black/lib/python3.9/site-packages/regex/_regex_core.py", line 21, in <modul
e>
    import regex._regex as _regex
ImportError: dlopen(/Users/scott/.vim/black/lib/python3.9/site-packages/regex/_regex.cpython-39-darwi
n.so, 2): no suitable image found.  Did find:
^I/Users/scott/.vim/black/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: code signatu
re in (/Users/scott/.vim/black/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so) not val
id for use in process using Library Validation: Trying to load an unsigned library
Error detected while processing function black#Black:
line    1:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'Black' is not defined

@scottwn
Copy link
Author

scottwn commented Oct 19, 2021

Reinstalled regex in the venv and it worked; I will work on a PR to update the doc or see if it can be fixed in vim-plug installation.

@johangp
Copy link

johangp commented Nov 10, 2021

Hi, I had the same issue. In my case, removing the "~/.local/share/nvim/black" folder did the work. However, I'm pointing to main instead of the stable branch due to this issue #2503

@AntiCompositeNumber
Copy link

Having the same issue, but with Vundle instead of vim-plug. Removing the ~/.vim/black/ folder worked.

@samuel-emrys
Copy link

samuel-emrys commented Jan 22, 2022

I'm having this issue, but nuking ~/.vim/plugged/black doesn't seem to have any effect.

Contents of my ~/.vimrc:

call plug#begin('~/.vim/plugged')
Plug 'psf/black', { 'branch': 'stable' }
call plug#end

:PlugInstall appears to successfully install black, and re-running it I get:

- black: Already installed

The traceback of the error I'm getting is:

Error detected while processing /home/user/.vim/plugged/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

This happens both when I do and don't have a virtualenv activated. I'm getting this in vim 8.2 on arch linux. Any guidance on how to resolve would be appreciated.

EDIT:

I tried both of the following alternatives as suggested by #2503, to no effect

Plug 'psf/black', { 'branch': 'main' }
Plug 'psf/black', { 'tag': 'stable' }

@AntiCompositeNumber
Copy link

Try removing .vim/black, update your plugins, then run :Black. That will reinstall the virtual environment to match the current system Python version.

@samuel-emrys
Copy link

Try removing .vim/black, update your plugins, then run :Black. That will reinstall the virtual environment to match the current system Python version.

Yep this was it, thanks. Didn't see that the virtualenv was there :)

@DanielWicz
Copy link

I have the same bug, but removing and reinstalling does not help.

I did the fallowing to solve the problem:

  1. Removed black from .vim/bundle
  2. Removed black from .vim
  3. Installed Black by PluginInstall
  4. 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

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

Successfully merging a pull request may close this issue.

5 participants