elpy
elpy copied to clipboard
Elpy fails to detect Black if a project module has a name conflicting with Black's modules.
Summary
The ’black’ formatter is not installed, please install it using ‘elpy-config’ or choose another one using ‘elpy-formatter’
I found that this error happens in some buffers but not others. The cause is python prepending '' to sys.path when
called with the -c option, which Elpy does in the function elpy-config--package-available-p and probaby in other
places.
Steps to reproduce
- Configure Elpy to use Black for formatting.
- Create a directory containing two files:
formatme.pyandsecrets.py. - Ensure that importing
secrets.pywill result in an error. - Try to format code in
formatme.pyusingelpy-format-code.
When Elpy tries to check for Black by importing it with python -c "import black", it will
fail because Black contains a module called secrets.py, but it'll import your erroneous version
because of '' getting prepended to sys.path.
To stop '' from getting prepended to sys.path, it is necessary to write the Python command
to be executed to a file and them have Python execute the file.
Result of (elpy-config)
# Paste it here
Elpy configuration in my init.el
# Paste it here