Your problem is that you use .py file as a command. You need to add python to tell which program can execute this code.

Alternatively, you can use black executable if it is installed in your python environment.

Answer from stasdeep on Stack Overflow
🌐
JetBrains
blog.jetbrains.com › pycharm › 2023 › 07 › 2023-2-eap-5
PyCharm 2023.2 EAP 5: Black Formatter Integration, Endpoints Tool Window for Django REST Framework | The PyCharm Blog
January 17, 2024 - You can run Black either on code reformat (by pressing ⌘⌥L / Ctrl+Alt+L or selecting Code | Reformat Code from the main menu) instead of the built-in formatter or when you are saving changes to your files.
🌐
Read the Docs
black.readthedocs.io › en › stable › integrations › editors.html
Editor integration - Black 26.3.0 documentation
Note that if you are using a virtual environment detected by PyCharm, this is an unneeded step. In this case the path to black is $PyInterpreterDirectory$/black. ... Description: Black is the uncompromising Python code formatter.
Discussions

PyCharm - How to enable Black Formatting globally
This does not appear to he possible. When you go into settings from the launcher (ie, no opened projects) the Black section of the tools settings does not appear. In addition, if you hover over the square-in-a-square icon next to black, it tells you explicitly that it's a project-specific setting. Consider submitting a bug about this if you can't find an existing one? More on reddit.com
🌐 r/Python
4
2
September 18, 2023
python - Issue using Black formatter in PyCharm - Stack Overflow
I am trying to setup the formatter "black" to work with PyCharm. I have tried setting it up with both the standard External Tools preferences and using the Files Watcher Plugin. Neither has worked ... More on stackoverflow.com
🌐 stackoverflow.com
How to add additional settings to Black formatter in pycharm - Stack Overflow
I just added the Black formatter to pycharm, and am trying to tweak the settings a bit on how the formatting should go. I'm working with a partner who uses vscode, and these are the settings he use... More on stackoverflow.com
🌐 stackoverflow.com
Can't get Black formatter to work
Looks like there's an error with the file path. It seems to be splitting the file path at the space. Try wrapping the path in just single quotes, or even single quotes and double quotes. EDIT Your path on the right has no quotes at all. That would explain why it's being split at the space. Make sure all file paths are wrapped in quotes then try again. More on reddit.com
🌐 r/pycharm
8
0
January 14, 2023
🌐
Medium
akshay-jain.medium.com › pycharm-black-with-formatting-on-auto-save-4797972cf5de
Pycharm + Black with Formatting on Auto-save | by Akshay Jain | Medium
June 11, 2021 - Pycharm + Black with Formatting on Auto-save So, lately, I’ve been working with Black for Python code formatting. Pretty cool huh! I’ve seen Black do wonders to my code. It made my (already …
🌐
JetBrains
plugins.jetbrains.com › plugin › 10563-black-pycharm
black-pycharm - IntelliJ IDEs Plugin | Marketplace
Reformat (local) python code using black. Requirement: + `black` must be pre-installed.
🌐
Xebia
xebia.com › home › blog › partial python code formatting with black & pycharm
Partial Python Code Formatting With Black & PyCharm | Xebia
December 10, 2018 - I created a small Bash script to call as external tool in PyCharm. Note the sed commands are MacOS specific: #!/usr/bin/env bash set -x black=$1 input_file=$2 start_line=$3 end_line=$4 # Read selected lines and write to tmpfile selection=$(sed -n "$start_line, $end_line p; $(($end_line+1)) q" < $input_file) tmpfile=$(mktemp) echo "$selection" > "$tmpfile" # Apply Black formatting to tmpfile $black $tmpfile # Delete original lines from file sed -i "" "$start_line,$end_line d" $input_file # And insert newly formatted lines sed -i "" "$(($start_line-1)) r $tmpfile" $input_file
🌐
The Murph's Blog
themurph.hashnode.dev › configure-black-in-pycharm
Configure Black in Pycharm - The Murph's Blog
August 16, 2024 - Within the Tools -> Black section: Select the instance of Python you would like to use, in my instance, I have selected Python from my virtual environment and then add any commands you would like present within the Settings section. I have not provided a path to any files being formatted as this is only formatting the file being saved, but I have still opted to override the maximum line length with the -l flag.
Find elsewhere
🌐
DEV Community
dev.to › zev › how-to-get-black-working-in-pycharm-in-2021-41k
How To Get Black Working in PyCharm in 2021 - DEV Community
June 11, 2021 - I remapped the "reformat code" keyboard shortcut to invoke BlackConnect. Making it work on startup requires an extra step, though: I made an on_pycharm_startup.sh file containing a single command blackd, did chmod +x on it, then added it to Tools>Startup Tasks.
🌐
YouTube
youtube.com › watch
Automate Python code formatting with Black. How to get started and add it to PyCharm - YouTube
In this video, I'll guide you through the process of installing and getting started with Black, a popular code formatter for Python. I'll show you how to add...
Published   February 28, 2021
🌐
JetBrains
jetbrains.com › help › pycharm › lsp-tools.html
Python tools support | PyCharm Documentation
December 19, 2025 - You can use Black to format your Python code in PyCharm. Disable overlapping formatting in Ruff if using together with Black to prevent conflicts
🌐
JetBrains
blog.jetbrains.com › pycharm › 2023 › 07 › 2023-2
PyCharm 2023.2: New Live Templates for Django, Black Formatter Integration, Run Anything, and AI Assistant | The PyCharm Blog
July 26, 2023 - PyCharm 2023.2 includes integration with the Black formatter. If you already have Black installed, PyCharm will detect it and suggest setting it up for your project. In PyCharm, Black works with .py and .pyi files. Whole files and file fragments can both be formatted.
🌐
Reddit
reddit.com › r/pycharm › can't get black formatter to work
r/pycharm on Reddit: Can't get Black formatter to work
January 14, 2023 -

I have spent all night on this... Things I've tried:

  • pip install black

  • pip install black[d] #this is the BlackConnectPlugin

  • Set up an external tool entry

When I run black, this is the error that comes up:

I tried on my laptop, it's the same error... Please help...

silver badge if you can help me figure this out... :,

-----------------------UPDATE FRIDAY----------------------------

Selecting blackd path in Settings > Tools

When I click on the following button, the script just does nothing.

someone ... please.... help me to fix this ToT

🌐
JetBrains
youtrack.jetbrains.com › issue › PY-39750 › Black-code-style-make-PyCharm-formatter-Black-compatible
Black code style: make PyCharm formatter Black compatible
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
GitHub
github.com › psf › black
GitHub - psf/black: The uncompromising Python code formatter · GitHub
Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting.
Starred by 41.4K users
Forked by 2.7K users
Languages   Python
🌐
JetBrains
jetbrains.com › help › pycharm › reformat-and-rearrange-code.html
Reformat and rearrange code | PyCharm Documentation
January 6, 2026 - Switch to the Formatter tab and enable the Turn formatter on/off with markers in code comments option.
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-30757 › Use-Black-tool-to-reformat-code-in-PyCharm
Use Black tool to reformat code in PyCharm : PY-30757
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong