13

I need to debug an py-script in PyCharm that makes use of unix binaries like "which, grep" and so on.

If I start the py-script from Terminal (bash), unix binaries are found and all works like expected. If I start the script from PyCharm "Debug" or "Run", there seems to be no "PATH" set => the unix binaries were not found.

Am I missing sth.?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
ierror
  • 513
  • 2
  • 6
  • 13
  • 1
    That's some longstanding bug! Here's a Youtrack reference, vote: https://youtrack.jetbrains.com/issue/PY-17816 – Victor Sergienko Nov 24 '16 at 00:14
  • If using zsh, all JetBrains products setup $PATH incorrectly, affecting both the builtin terminal and running/debugging files in the IDE. You can see if this bug is affecting you by creating a pycharm file with `import os; print(os.getenv('PATH’,’’)`, running it, and comparing output to `echo $PATH` in the builtin terminal and an OS shell. I have a fix on *nix/mac here (stackoverflow.com/a/51006003/1089228). Note: their bash startup file execution is set up correctly - if you are having problems with another shell, the above answer should provide enough info to guide you to a solution. – Steve Tarver Jun 25 '18 at 18:06

3 Answers3

17

Add the PATH environment variable to your Run Configuration (Run->Edit Configurations…) like this: /usr/local/bin:$PATH

Kentzo
  • 3,881
  • 29
  • 54
1

Create a new environment variable in your run configuration named PATH, and set it equal to the output of running echo $PATH on your command line. This will let you get around the issue.

Myer
  • 3,670
  • 2
  • 39
  • 51
-2

I have had to manually symlink binaries that are in your PATH, but not in /usr/bin/. For example, scripts running 'ffmpeg' in pycharm will not see /usr/local/bin/ffmpeg but after symlinking will be able to see /use/bin/ffmpeg. This is a python subprocess issue (they don't consult your .bashrc as bash does).

Lincoln B
  • 2,184
  • 1
  • 13
  • 12
  • bash does *not* look into the `.bashrc` when resolving paths. It looks at the `PATH` environment variable, just as subprocess. Try running `source ~/.bashrc && pycharm` and see if that helps. – vidstige May 07 '15 at 11:17