Pycharm设置正确的环境变量PATH [英] Pycharm set the correct environment variable PATH

查看:1119
本文介绍了Pycharm设置正确的环境变量PATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm executing with pycharm the following:

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

但是当我在shell中执行echo $ PATH时,会返回:

But when I execute echo $PATH in a shell this is returned:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin

我尝试在偏好设置">控制台">"Python控制台">环境变量"中进行设置,

I tried to edit it in Preferences > Console > Python Console > Environment Variables, setting

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin

但这不起作用

有什么主意吗?

推荐答案

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

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

  1. 在Mac上
  2. 使用bash(也许是zsh)以外的其他外壳

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

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

如果使用的是zsh,则可以通过编辑终端插件的.zshrc来解决该根本问题.假设PyCharn位于应用程序"文件夹中,请打开/Applications/PyCharm.app/Contents/plugins/terminal/.zshrc并将其内容替换为:

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

如果您对所有详细信息感兴趣,或者想了解我如何解决此问题,以便为另一个外壳开发解决方案,请参见以下答案:

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

这篇关于Pycharm设置正确的环境变量PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆