为什么 ipython env 变量与相关终端仿真器中的 bash env 不匹配?

Why don't the ipython env variables match the bash env in the associated terminal emulator?

最近我在Python做一些互动工作。

我的设置是 IPython 笔记本 运行 在使用网格引擎管理作业的服务器上。

今天我试图让一个 IPython 集群按照 here 发布的一个示例运行,该示例使用 subprocess.Popen 启动一个集群。

我无法让示例运行,所以我尝试打开 IPython/Jupyter 终端仿真器并输入 ipcluster start 命令,然后集群立即启动了!

玩了一会儿之后,我意识到如果我在终端仿真器中输入 env,我得到的环境变量列表与我在 os.environ 中查看的变量不同。 =50=]。问题的根源似乎是 PATH 变量不同。

现在我知道我可以更改 os.environ 中的 PATH 变量,但我想知道为什么它首先不同?我对环境变量知之甚少,所以这可能是一个愚蠢的问题,但我假设终端仿真器和笔记本 运行 在完全相同的 IPython 笔记本服务器中的完全相同的节点上会有具有完全相同的环境变量。

任何关于为什么终端和笔记本中的环境变量可能不同的见解将不胜感激。

更新: 以防万一,我正在使用的服务器使用 Univa Grid Engine。我还注意到使用 qrshqsub 启动笔记本服务器似乎有所不同。

以前我一直在使用 qsub,但是通过使用 qrsh 启动笔记本服务器,我消除了 envos.environ 之间的许多差异。差异仍然存在,但要少得多。仍然不确定这意味着什么:)

根据 qsub、qsh、qrsh 的手册页,要将当前 shell 环境传播到作业,请使用 -V 选项:

 -V     Available for qsub, qsh, qrsh with command and qalter.

        Specifies that all environment variables active within the qsub utility be exported to the context of the job.

        All environment variables specified with -v, -V or the DISPLAY variable provided with -display will be exported to the defined JSV  instances  only  optionally  when  this  is
        requested explicitly during the job submission verification.  (see -jsv option above or find more information concerning JSV in jsv(1))