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

Vim plugin unable to install black on certain machines #672

Closed
joaqo opened this issue Jan 17, 2019 · 9 comments
Closed

Vim plugin unable to install black on certain machines #672

joaqo opened this issue Jan 17, 2019 · 9 comments
Labels
C: integrations Editor plugins and other integrations C: packaging Installation and packaging of Black C: vim Vim plugin

Comments

@joaqo
Copy link

joaqo commented Jan 17, 2019

Operating system: Ubuntu 18.04
Python version: 3.6.6
Black version: whichever version the vim plugin is trying and failing to install
Does also happen on master: see above

Hey, I installed and used the vim black plugin perfectly fine on macOS, but when I tried it in ubuntu I ran into some problems.

During installation with vim-plug i get the following error: No module named 'black'. Not sure why this is, I did the same exact thing I was doing in macOS, and I am not in any virtualenv or anything weird. The ubuntu machine has python2.7 (under python) and python3.6.6 (under python3) installed. No idea why this could be happening. After this failed installation, each time i try to open vim I get the same error message. Tried installing several times, always get the same error.

Thanks for the awesome project btw!

Edit: The only way I can start vim without getting the error message is if I run it in a virtualenv that has black installed, after this black runs fine. But if I dont do this I get the error mistake.

@theydonthaveit
Copy link

theydonthaveit commented Jan 25, 2019

Hi, I have a similar issue (on Ubuntu). Black works fine in VScode and within virtualenv. Adding black to Vim via Plug or manually. I can't seem to get it working
When running :Black - result below

Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'Black' is not defined

opening a *.py file

Error detected while processing ~/.vim/plugged/black/plugin/black.vim:
line  124:
Traceback (most recent call last):
  File "<string>", line 56, in <module>
ModuleNotFoundError: No module named 'black'

opening black.vim file

Error detected while processing ~/.vim/plugged/black/plugin/black.vim:
line  124:
Traceback (most recent call last):
  File "<string>", line 56, in <module>
  File "/home/imbatmam/.vim/plugged/black/black.py", line 39, in <module>
    from appdirs import user_cache_dir
ModuleNotFoundError: No module named 'appdirs'

@kshcherban
Copy link

For me issue was fixed after Python3.7 was installed as system python3 interpreter.

@ronalabraham
Copy link

ronalabraham commented Mar 7, 2019

I have a workaround that I hope will help anyone else with this error.

Firstly, I am using a similar setup as @joaqo:

Operating system: Ubuntu 18.04
Python version: 3.6.7 (i.e. $ python3 --version prints "Python 3.6.7")

I use Vundle, so my .vimrc has Plugin 'ambv/black'. I also have let g:black_virtualenv="~/.vim_black". The first time I opened vim with the plugin installed, I got the following output:

$ vim black.vim
Please wait, one time setup for Black.
Creating a virtualenv in /home/ronalabraham/.vim_black...
(this path can be customized in .vimrc by setting g:black_virtualenv)
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
    apt-get install python3-venv
You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.
...etc

So I did exactly what the output recommended: sudo apt-get install python3-venv. Re-opening vim then installed Black correctly in the expected directory:

$ vim
Please wait, one time setup for Black.
Creating a virtualenv in /home/ronalabraham/.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 ✨ 🍰 ✨

This fixed the ModuleNotFoundError: No module named 'black' error when re-opening vim in the future!

@JelleZijlstra JelleZijlstra added C: packaging Installation and packaging of Black C: integrations Editor plugins and other integrations labels May 5, 2019
@raphapassini
Copy link

In adition to the super useful comment of @ronalabraham
What worked for me was:
sudo apt-get install python3-venv
python3 -m venv ~/.vim_black
source ~/.vim_black/bin/activate
pip install black

Then inside the .vimrc I added g:black_virtualenv="~/.vim_black"

Seems that if you only g:black_virtualenv="~/.vim_black" and try to install the plugin (at least with vim-plug) it will not properly create the venv with black for you.

I'm not sure if this is a bug, it seems not, but it wasn't clear for me that I should be the one setting the venv, maybe worth some mention about this in the documentation.

@rollschild
Copy link

Any activities on this issue recently? I'm using Vim 8.1 and hitting the same error. Tried the solutions mentioned above but no success. Still the same error. However, NeoVim does work correctly. One thing I'm extremely confused is the exact order in which I install black, activate the virtualenv, and install the black vim plugin. Any help would be extremely appreciated.

@kontsaki
Copy link

kontsaki commented Mar 3, 2020

@rollschild try to remove the directory that g:black_virtualenv is referencing and open vim again

@ambv
Copy link
Collaborator

ambv commented Mar 4, 2020

This is usually caused by Python and/or Vim upgrading under you while an old virtualenv is still around. The plugin should gracefully say that the virtualenv is unusable. I'd accept a PR to this effect. We have other priorities at the moment.

@richtong
Copy link

OK, the simplist fix I've seen on a mac for this is to reinstall black with

rm -f ~/.vim/black

Which causes a new environment to get downloaded. You could also try :BlackUpgrade

@JelleZijlstra JelleZijlstra added the C: vim Vim plugin label May 29, 2021
@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
C: integrations Editor plugins and other integrations C: packaging Installation and packaging of Black C: vim Vim plugin
Projects
None yet
Development

No branches or pull requests