Yapf: How do I install yapf in pycharm

Created on 12 Oct 2018  路  11Comments  路  Source: google/yapf

Most helpful comment

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.

Preferences
Preferences

All 11 comments

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 -> + -> . My settings include:

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.

  1. install it via pip or conda
  2. install the plugin in pycharm e.g. from marketplace or from file
  3. Make sure your executable is at the right location:
  4. In Pycharm choose Preferences->Tools:
  5. look at YAPF Settings section -> Executable path
  6. 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:
screenshot 2019-02-10 at 18 26 41

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:

screenshot 2019-02-10 at 18 26 41

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

Screen Shot 2019-06-21 at 3 47 11 PM

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.

Preferences
Preferences

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jrwrigh picture jrwrigh  路  6Comments

haphut picture haphut  路  3Comments

tschijnmo picture tschijnmo  路  6Comments

hayd picture hayd  路  8Comments

Harkirat155 picture Harkirat155  路  7Comments