Hongyi Zhao <
hongy...@gmail.com>:
>On Mon, 16 Dec 2019 13:01:22 +0000, Hongyi Zhao wrote:
>
>> eval "$(pyenv init -)"
>> eval "$(pyenv virtualenv-init -)"
>> eval "$(pipenv --completion)"
>
>I've done the test on the above commands in the (), and found the
>following results:
>
>Each of them will expanded into some very complex compound commands/
>functions as follows:
>
>
>-------------- begin from here --------------
>$ pyenv init -
>export PATH="/home/werner/.pyenv/shims:${PATH}"
>export PYENV_SHELL=bash
>source '/home/werner/.pyenv/libexec/../completions/pyenv.bash'
>command pyenv rehash 2>/dev/null
>pyenv() {
[…]
>}
>
>
>$ pyenv virtualenv-init -
>export PATH="/home/werner/.pyenv/plugins/pyenv-virtualenv/shims:${PATH}";
>export PYENV_VIRTUALENV_INIT=1;
>_pyenv_virtualenv_hook() {
[…]
>};
[…]
>
>-------------------- end at here ----------------
>
Thank you for showing the output.
>I just want to know whether in this case, it's not feasible for running
>them in .profile with eval.
>
It does make sense and it doesn't make sense to run those "eval"
commands from the file “~/.profile”:
The commands
“eval "$(pyenv init -)"”
and
“eval "$(pyenv virtualenv-init -)"”
both prepend something to the PATH environment variable.
Therefore it's not very useful to let them run from “~/.bashrc”,
because then they will be run from each interactive (subshell)
bash. For example, imagine, you have an interactive shell running
in a terminal or terminal emulator, then start an editor out of
it. In the editor, you start an interactive shell. Then this
shell will have the PATH environment variable extended twice by
the pyenv‐initializing commands.
=> The “eval "$(pyenv …)"” commands should better be run from
“~/.profile” rather than from „~/.bashrc“.
But now you'll get into another problem:
These initializing commands not only prepend something to the PATH
environment variable, but also define some functions. But
functions (by default) are not exported to the environment.
=> If you put these commands for example into “~/.xinitrc”, the
environment will be initialized and then be inherited by any shell
running in a terminal window. That's fine. But the defined
functions will not be inherited by any shell running in a terminal
window.
=> The problem is, that the task done by the “eval "$(pyenv …)"”
commands should be split: into the environmental part, which
should be run from “~/.profile” or “~/.xinitrc”, and the function
definition part, which should be run from “~/.bashrc”.
As far as I can see you cannot do much to solve that problem
(apart from filing a bug report to the developers of the python
environment).