0

I installed YAPF formatter for Python code. Installation was successfull, no errors. Python 2.7.12

pip install yapf

Can't figure out how to run it: when run yapf -h, I get error 'unknown command'. Same when run python yapf -d file.py

Output of test commands:

$ type -a pip yapf
pip is /usr/bin/pip
bash: type: yapf: not found

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

$ ls -l {~/.,/usr/}local/bin/yapf
ls: cannot access '/usr/local/bin/yapf': No such file or directory
-rwxrwxr-x 1 username username 213 Jul 25 00:17 /home/username/.local/bin/yapf
minto
  • 831
  • Can you add the output of type -a pip yapf and echo $PATH and ls -l {~/.,/usr/}local/bin/yapf please? – Byte Commander Jul 25 '18 at 09:49
  • @Byte Commander I added output into in the top. – minto Jul 25 '18 at 17:34
  • When you use pip install --user, your executables end up in ~/.local/bin, which only recently got added to the default PATH environment variable. On vanilla 16.04 Ubuntu installations or older, this directory might be missing in there, so that you can't directly execute those as commands without specifying their location. More details in the post linked above. – Byte Commander Jul 25 '18 at 21:16
  • So YAPF does not work out of the box on normal ubuntu 16.04LTS installation. – minto Jul 26 '18 at 00:03
  • It works if you install it system-wide (sudo -H pip install yapf), because then the executable is placed in /usr/local/bin, which is on the default PATH. If you install it for the user only (pip install --user yapf), it's placed in ~/.local/bin, which is not on the default PATH, but easy to add, as described in the linked post. You could also just e.g. make a link in ~/bin to your executables, as that folder gets added to the path automatically. – Byte Commander Jul 26 '18 at 08:04
  • But I installed it via pip install yapf, not via pip install --user yapf. – minto Jul 26 '18 at 13:26
  • Look at @ByteCommander's comment again, it uses sudo -H. I think the --user flag is the default in recent versions anyway. Also this is not YAPF specific, this is for all packages with an executable. – Timo Jul 27 '18 at 07:30
  • I added ~/.local/bin to the $PATH environment variable as suggested, that helped. One note: when editing ~/.profile file, should I insert blank line between existing variables and my new path variable, or this doesn't matter? – minto Jul 27 '18 at 08:29

0 Answers0