13

I'm learning python recently. And I use PyCharm as my editor running in a MacBook. The problem is when I type something like scrapy -V in my PyCharm terminal, it tells me that "zsh: command not found: scrapy", but when I launch my terminal outside PyCharm it works all right.

So I'm wondering if the path var is right. And then I tried echo $PATH in PyCharm terminal, it returns:

/usr/bin:/bin:/usr/sbin:/sbin

and the terminal outside PyCharm returns:

/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands

and I set shell path to: /bin/zsh

And by the way I'm IDEA too, but everything there works just fine, and the shell path is the same as what is in the PyCharm.

So, what is causing the path variable in my PyCharm terminal(zsh) to be wrong?

Liang
  • 1,127
  • 2
  • 11
  • 22

5 Answers5

21

For me, adding this to the beginning of the ~/.zshrc file helped:

# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
Daniel Dror
  • 2,304
  • 28
  • 30
5

I encounter this problem with zsh. Specifically, I lose /usr/local/bin from PATH. This is filed in the Pycharm bug tracker - so there does not seem to be a real fix for it.

However, starting Pycharm directly from the Terminal via the charm command results in the correct PATH.

nbro
  • 15,395
  • 32
  • 113
  • 196
Robbotnik
  • 557
  • 8
  • 8
1

I think that this is a problem from PyCharm not inheriting correctly the variables. Here is the link https://intellij-support.jetbrains.com/hc/en-us/community/posts/208567485-Pycharm-terminal-is-missing-part-of-PATH

PlugaruT
  • 154
  • 7
0

I add echo $PATH at the top of ~/.zshrc, and terminal prints /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/aria2/bin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS while the pycharm shell prints /usr/bin:/bin:/usr/sbin:/sbin.

So it seems that /usr/libexec/path_helper is not called in pycharm shell. You can add eval $(/usr/libexec/path_helper) at the top of ~/.zshrc,but it's slow and it's better to add paths manually like export PATH=$HOME/bin:/usr/local/bin:$PATH.

mearlosy
  • 63
  • 2
  • 7
0

Hi in my case (Pycharm 2018.3, Ubunt 16.04) it appears that it was related to the way I configure Zsh the first time while having PyCharm running.

I try all the above without success.

At some point I backup my .zshrc file and all the others .zsh files .zsh_history... I deleted all the zsh related file while the terminal and PyCharm closed too. Then I started terminal get prompt to configure Zsh for the first time, select Recommanded way of configure the new install. Close my Term, start it back, Zsh was now default shell. Then start PyCharm et voilà!!

No more problem. And PyCharm laungh the terminal with shell in pipenv which wasn't the case when I was having the problem.

There were some mix up with Byobu too, as now byobu is launch at startup in terminal but in Pycharm Byobu is not there which is good. Previously both terminal and Pycharm terminal were kind of a single instance, if I was existing one it exit the other instance (single instance in fact).

Richard
  • 721
  • 5
  • 16