本文介绍了设定Pyenv的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在服务器.bashrc文件中设置Pyenv的加载路径.

I am trying to set the load path for Pyenv in my server .bashrc file.

我正在关注教程,它要求我们将pyenv设置为加载路径

I am following this tutorial where it asks us to set pyenv to the load path

但是,在我的.bashrc文件中,我已经看到了以下命令

However, in my .bashrcfile, I already see the below commands

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
 eval "$(pyenv init -)"
fi

与上面共享的教程中提供的以下内容有何不同?

And how is it different from the below provided in the tutorial shared above?

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

我可以知道上面所示代码中的if...fi块做什么吗?

May I know what does if...fi block does in the code shown above?

推荐答案

主要是bash的语法.

It's mostly bash's syntax.

#1.

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"

等同于

export PATH="$HOME/.pyenv/bin:$PATH"

在第一种情况下,您先声明一个名为PYENV_ROOT的变量,然后使用它.

as in the first case, you're declaring a variable named PYENV_ROOT then using it.

#2.

iffi是在bash中编写if语句的方式.

if and fi are how you write if-statements in bash.

#3.

command -v pyenv 用于在在这种情况下,-v选项将打印路径名,例如

command -v pyenv is used to execute a command (pyenv) in this case, the -v option prints the pathname e.g.

$ command -v python
/usr/bin/python
if command -v pyenv 1

表示如果找到命令pyenv,则执行eval "$(pyenv init -)"

means that if the command pyenv is found, then execute eval "$(pyenv init -)"

#4.

在这里,>/dev/null 2>&1;用于丢弃输出.了解有关此内容的更多信息此答案.

Here, >/dev/null 2>&1; is used to discard the output. read more about it this answer.

因此,两个代码块几乎相同,唯一的区别是:第一个代码具有if-block,第二个代码具有一个额外的命令eval "$(pyenv virtualenv-init -)".

Hence, two blocks of code are almost same, the only differences are: the first one has a if-block and second one has one extra command eval "$(pyenv virtualenv-init -)".

这篇关于设定Pyenv的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 13:31