我正在用pycharm执行以下操作:

print(os.environ["PATH"]) # returns '/usr/bin:/bin:/usr/sbin:/sbin'

但是,当我在shell中执行echo $ PATH时,将返回:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin

我试图在“首选项”>“控制台”>“Python控制台”>“环境变量”中进行设置,
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin
但这不起作用

任何想法?

最佳答案

@ fj123x,我将从您的帖子中猜测您是

在Mac上

  • 使用除bash(也许是zsh)以外的 shell

  • 如果为true,则问题是JetBrains jediterm终端仿真器未按正确的顺序执行所有Shell启动文件。

    如果您使用的是zsh,则可以通过编辑终端插件的.zshrc来解决该根本问题。假设PyCharn位于“应用程序”文件夹中,请打开/Applications/PyCharm.app/Contents/plugins/terminal/.zshrc并将其内容替换为:
    #!/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 moving
    bindkey '^[^[[C' forward-word
    bindkey '^[^[[D' backward-word
    
    ZDOTDIR=$_OLD_ZDOTDIR
    
    if [ -n "$JEDITERM_USER_RCFILE" ]
    then
      source "$JEDITERM_USER_RCFILE"
      unset JEDITERM_USER_RCFILE
    fi
    
    if [ -n "$ZDOTDIR" ]
    then
      DOTDIR=$ZDOTDIR
    else
      DOTDIR=$HOME
    fi
    
    if [ -f "/etc/zshenv" ]; then
         source "/etc/zshenv"
    fi
    
    if [ -f "$DOTDIR/.zshenv" ]; then
         source "$DOTDIR/.zshenv"
    fi
    
    if [ -n $LOGIN_SHELL ]; then
      if [ -f "/etc/zprofile" ]; then
           source "/etc/zprofile"
      fi
      if [ -f "$DOTDIR/.zprofile" ]; then
           source "$DOTDIR/.zprofile"
      fi
    fi
    
    if [ -f "/etc/zshrc" ]; then
         source "/etc/zshrc"
    fi
    
    if [ -f "$DOTDIR/.zshrc" ]; then
         source "$DOTDIR/.zshrc"
    fi
    
    if [ -n $LOGIN_SHELL ]; then
      if [ -f "/etc/zlogin" ]; then
           source "/etc/zlogin"
      fi
      if [ -f "$DOTDIR/.zlogin" ]; then
           source "$DOTDIR/.zlogin"
      fi
    fi
    
    if [ -n "$JEDITERM_SOURCE" ]
    then
      source $(echo $JEDITERM_SOURCE)
      unset JEDITERM_SOURCE
    fi
    

    如果您对所有详细信息感兴趣,或者想了解我如何解决此问题,以便可以为另一个 shell 开发解决方案,请参见以下答案:https://stackoverflow.com/a/51006003/1089228

    10-06 06:25