13
votes

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.?

Thank you very much for help, Börni

3
That's some longstanding bug! Here's a Youtrack reference, vote: youtrack.jetbrains.com/issue/PY-17816 - Victor Sergienko
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

3 Answers

17
votes

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

1
votes

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.

-2
votes

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).