-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Installed black via vim-plug on macOS; starting vim throws ModuleNotFoundError: No module named 'black' #1379
Comments
This is the error with which the Black virtualenv setup fails:
Note the last line, the command starts with I've done a bit of spelunking and I think it's ultimately a bug in newer versions of Vim. I've proposed a workaround in #1380. Can you please try it out and report back whether it was of any help, @erikr? |
More precisely: It turns out it's actually a bug in Vim for which |
@dlukes Fantastic detective work! I edited my
Is there something else I need to change? Thanks! |
After editing |
Thanks, progress!
Installation took a long time (2 minutes), but it solved this particular error. I think your PR #1380 should be linked to this issue to automate closure. Now there is a new problem:
I thought this error was addressed by #1273. Suggested next move? |
This is the error resulting from incompatible versions of cd ~/.vim
black/bin/pip install --upgrade git+https://github.com/psf/black.git |
Success! Thanks for your patience and clear explanations! I was confused about the difference between release and Should I close this issue or wait for your PR to close it? |
@erikr Waiting for PR is recommended. Unless this issue is unrelated to that pull request. |
Sorry for not making that clear enough earlier :) The trouble basically is that Vim plugin managers default to installing from the So you need to override the defaults either for the plugin so that both are the latest stable release (that's what the new install instructions recommend), or for the Python library so that both are the latest development version from the With recent versions of Vim, only the second option works, because the latest stable release of You might want to check back at some point in the future whether a new stable release of Black has been made with support for recent versions of Vim, and if so, consider switching away from the bleeding edge, as it's safer / more convenient (e.g. because you don't need to mess with FYI, while tweaking the PR, I also ran into this fun little problem you might encounter with Vim + Python. If you're not too heavily invested in Vim-specific features, maybe it would be worth it to try out Neovim. Admittedly, I've also had my fair share of Python-related troubleshooting with Neovim, but at least it works with Black's latest stable release, and the issues were generally less weird than " |
|
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
@dlukes I now have a new error that is introduced after cd ~/.vim
black/bin/pip install --upgrade git+https://github.com/psf/black.git (which still addresses the cannot find pyproject.toml bug) Now, when I call
I reproduced this on Ubuntu 20.04 and macOS 10.15.5, both in Python 3.8.3, Vim 8.1 with +Python3 support, Have you seen this? I am not sure how to troubleshoot it so any input is appreciated! |
Try running In that case, it would be great if you could reduce your Python source file to the smallest possible example that triggers the error and file an issue. That's one of the joys of living at the bleeding edge -- you get to spend more time reporting bugs. You can try installing progressively older versions of If your Vim config is not too complicated, it might also be worth it to switch to Neovim, as I suggested previously, so that you can simply use stable |
I identified the problem is with Thanks for the prompt and helpful reply! |
Great, well done! |
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
I had this problem when I used the stable copy of black.vim. Installing the HEAD copy fixed the bug. Edit: never mind, now I have the find_pyproject_toml bug 🤦 |
Just to provide my solution... : According to my understanding, the black plugin is installed in folder '.vim/plugged/black' (I am using vim-plug)
exit python and do Then the problem seems to be solved. Feel free correct me if something is wrong. |
Also, you can add 'print(virtualenv_site_packages)' on line 80 in file '.vim/plugged/black/plugin/black.vim' to see where vim? is looking for the black package and the what version the python should be in the virtual environment. |
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
Had the same issue again after updating Vim via homebrew (Vim is now built with Python 3.8 vs 3.7 previously) causing the the same ModuleNotFoundError error -- presumably since the venv no longer functions with a now-missing version of Python. I wrote this for my vim-plug configuration: function! UpdateBlack(info)
if a:info.status != 'unchanged' || a:info.force
silent !rm -rf ~/.vim/black
redraw!
BlackUpgrade
endif
endfunction
Plug 'psf/black', { 'do': function('UpdateBlack') } Now the venv gets recreated if I |
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
To help format python files. Note some fiddling is required to install this correctly because > This is the error resulting from incompatible versions of black.vim > (the Vim plugin) and black.py (the Python library) we were previously > discussing in #1293 -- you have the master version of black.vim, which > however installs the latest release (i.e. code that's older than master) > of black.py. Since the latest release of black.vim doesn't work with > recent versions of Vim, your only option is to update black.py (so that > both black.vim and black.py are the same bleeding edge -- master -- > version). As per the instructions you provided in the OP: ``` cd ~/.vim black/bin/pip install --upgrade git+https://github.com/psf/black.git ``` From psf/black#1379 (comment)
Describe the bug
I get
ModuleNotFoundError: No module named 'black'
when I runvim
, and thus cannot use black invim
on macOS:Surely I am not the only macOS + vim user who wants to use black!
To Reproduce
Install
vim-plug
(link).Add
Plug 'psf/black'
next to the other plugins in~/.vimrc
.Install via
vim
followed by:PlugInstall
, or viavim -c PlugInstall
:Run
vim
from terminal.Expected behavior
I expect to not get that error, for
vim
to load, and for me to be able to use black as described in the README.Environment (please complete the following information):
vim-plug
installation instructions. Is it not master?Additional context
@akselsjogren suggested upgrading black used by the vim-plugin to the latest from master:
However I do not have
pip
inbin
and thus cannot try this:Also, see #1293 for further discussion and other things I've tried to fix.
The text was updated successfully, but these errors were encountered: