yapf
yapf copied to clipboard
How do I install yapf in pycharm
On the main menu, choose File -> Settings for Windows and Linux or press Ctrl+Alt+S Find Project Interpreter under the Project: [Your Project Name]. Click the green plus(+) and search for Yapf and install package
The best way I've found is to create a File Watcher. That is, go to Preferences -> File Watchers -> + ->
File Type: Python Scope: Open Files Program: yapf Arguments: -i $FilePathRelativeToProjectRoot$
Hope it helps! (Make sure you have installed yapf via pip install yapf in the computer PyCharm runs in.)
Hi @sevvalmehder and @bcollazo
I have followed your steps to add a package in the project interpreter and also add it to file watchers. I also pip install yapf and download the plugins. However, when I use Code -> Reformat code with YARF, it always say "YAPF executable is not found." Do I miss any step?
Hey @davislf2, it can be a number of things. Using the 'Reformat Code' seems like you are using the action provided by the plugin. I think that plugin expects yapf to be available in /usr/local/bin/yapf (https://github.com/binh-vu/yapf-pycharm/blob/master/src/ReformatCode.java#L45).
Do you have yapf there? yapf should be at the very least accessible from the command line in a new terminal for you. Also the output for which yapf in your command line should be helpful.
See autopep8-on-pycharm, they are the same except that you use yapf instead of autopep8. In addition, isort is configurated the same way. Best Wishes.
- install it via pip or conda
- install the plugin in pycharm e.g. from marketplace or from file
- Make sure your executable is at the right location:
- In Pycharm choose Preferences->Tools:
- look at YAPF Settings section -> Executable path
- You have to put your yapf executable at this location/path if it isn't already.
@spectralLight PyCharm 2018.3 in your step #3 there is no YAPF present anywhere in the settings:

The default location using pip install yapf is:
(base) Glenns-MBP:~ glennjocher$ which yapf
/anaconda3/bin/yapf
Could not get it to work using any of these suggestions. BTW, @spectralLight in PyCharm 2018.3 Community nothing shows up in this panel after installing the plugin, so I'm quite confused. There is no 'YAPF Settings section' as you mention:
If using the yapf-pycharm plugin (vs. the yapf plugin) then you have to have the yapf executable located at /usr/local/bin/yapf. One way to do this is to create a symbolic link:
ln -s $(which yapf) /usr/local/bin/yapf
I have it installed with anaconda, and I tried both the /usr/local/bin/yapf path with the softlink and the /anaconda3/bin/yapf path, but I'm still not seeing anything change on save. I'm on professional 2019.1
While the "yapf-pycharm" plugin for Pycharm did work for me after creating the symbolic link, I had issues combining it with a file watcher, and the "yapf" plugin simply would not operate the way I desired either.
I eventually added it to my external tools, and created a file watcher using it, and everything works perfectly.

While the "yapf-pycharm" plugin for Pycharm did work for me after creating the symbolic link, I had issues combining it with a file watcher, and the "yapf" plugin simply would not operate the way I desired either.
I eventually added it to my external tools, and created a file watcher using it, and everything works perfectly.
![]()
I tried many things but none of them worked. This is the perfect solution.
For whatever reason, I had to set arguments to -i $FilePath$ to pass the full file path to yapf, and leave "Working directory" blank. Otherwise, yapf kept complaining that I wasn't passing in a valid file. Otherwise, @Lygre's solution worked.