Skip to content Skip to sidebar Skip to footer

Pycharm Set The Correct Environment Variable Path

I'm executing with pycharm the following: print(os.environ['PATH']) # returns '/usr/bin:/bin:/usr/sbin:/sbin' But when I execute echo $PATH in a shell this is returned: /usr/local

Solution 1:

@fj123x, I'm going to guess from your post that you are

  1. on a mac
  2. using a shell other than bash (perhaps zsh)

If true, the problem is that the JetBrains jediterm terminal emulator is not executing all shell startup files in the correct order.

If you are using zsh, you can fix that root problem by editing the terminal plugin's .zshrc. Assuming PyCharn is in your Applications folder, open /Applications/PyCharm.app/Contents/plugins/terminal/.zshrc and replace the contents with:

#!/bin/zsh# starver mod# Jetbrains uses jediterm as a java terminal emulator for all terminal uses.# There are some apparent limits on use:# - must use old-style shebang - not the #!/usr/bin/env zsh# - must implement the startup file loading here## Note: original contents are in lib/terminal.jar# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word movingbindkey'^[^[[C' forward-word
bindkey'^[^[[D' backward-word

ZDOTDIR=$_OLD_ZDOTDIRif [ -n "$JEDITERM_USER_RCFILE" ]
thensource"$JEDITERM_USER_RCFILE"unset JEDITERM_USER_RCFILE
fiif [ -n "$ZDOTDIR" ]
then
  DOTDIR=$ZDOTDIRelse
  DOTDIR=$HOMEfiif [ -f "/etc/zshenv" ]; thensource"/etc/zshenv"fiif [ -f "$DOTDIR/.zshenv" ]; thensource"$DOTDIR/.zshenv"fiif [ -n $LOGIN_SHELL ]; thenif [ -f "/etc/zprofile" ]; thensource"/etc/zprofile"fiif [ -f "$DOTDIR/.zprofile" ]; thensource"$DOTDIR/.zprofile"fifiif [ -f "/etc/zshrc" ]; thensource"/etc/zshrc"fiif [ -f "$DOTDIR/.zshrc" ]; thensource"$DOTDIR/.zshrc"fiif [ -n $LOGIN_SHELL ]; thenif [ -f "/etc/zlogin" ]; thensource"/etc/zlogin"fiif [ -f "$DOTDIR/.zlogin" ]; thensource"$DOTDIR/.zlogin"fifiif [ -n "$JEDITERM_SOURCE" ]
thensource $(echo$JEDITERM_SOURCE)
  unset JEDITERM_SOURCE
fi

If you are interested in all the gory details, or you want to see how I solved this problem so you can develop a solution for another shell, see this answer: https://stackoverflow.com/a/51006003/1089228

Solution 2:

On Ubuntu, using zsh, I stumbled upon the same problem.

The hack I use in order to have the same environment variables in PyCharm and my shell is to launch PyCharm from my terminal instead of using the icon. It looks like this way that the PyCharm shell inherits from the main shell it's been launched from.

I hope it can solve other people's problem as I wasn't able to replicate @Steve Tarver's solution on Linux (.../terminal/.zshrc was read only on /snap/, even when using sudo).

Solution 3:

I work on the command line in bash and my environment, including $PATH, is set in .bash_profile. The default terminal in PyCharm is tcsh. I changed it to bash by going File ... Default Settings ... Tools ... Terminal ... Shell Path and then restaring. The embedded terminal worked as expected.

Post a Comment for "Pycharm Set The Correct Environment Variable Path"