I activated the formatting on save in the
init.el file uncommenting the following line
(format +onsave) ; automated prettiness
But when I save a Python file, I get the following error message:
Error (before-save-hook): Error running hook "+format-buffer-h" because: (error You need the "black" command. You may be able to install it via "pip install black".)
I installed black with pip, as the message says, but I keep getting the same message.
I set the following settings for the Python black formatter (found it here):
;; package.el (package! python-black)
;; config.el (use-package! python-black :demand t :after python :config (add-hook! 'python-mode-hook #'python-black-on-save-mode) ;; Feel free to throw your own personal keybindings here (map! :leader :desc "Blacken Buffer" "m b b" #'python-black-buffer) (map! :leader :desc "Blacken Region" "m b r" #'python-black-region) (map! :leader :desc "Blacken Statement" "m b s" #'python-black-statement) )
I did run
doom sync after changing the settings, and it installed some packages, but I still get the same error when saving Python files.
I'm using Fedora 34, and installed black for Python 3.9. I also tried to install black for Python 2.7, but it's not supported anymore, so I was guessing that maybe Emacs is expecting black to be installed for Python 2.7, That's only a conjecture because I'm new to Emacs and don't know much about it.
Is there a way to make Python formatting work?