python - Pyenv 用作 sudo 时不显示所有版本
问题描述
我使用 pyenv安装3.5.2
和版本。3.5.3
# pyenv versions
* system (set by /usr/local/pyenv/version)
3.5.2
3.5.3
但是,当我以sudo
(而不是以登录身份root
)运行此命令时,它并没有给我所有版本。
$ sudo /usr/local/bin/pyenv versions
* system (set by /root/.pyenv/version)
我尝试使用设置PYENV_ROOT
路径,但这也不起作用。
$ export PYENV_ROOT=/usr/local/pyenv/
$ sudo /usr/local/pyenv/bin/pyenv versions
* system (set by /root/.pyenv/version)
我已经.bash_profile
在 myuser中设置了路径
$ cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export PYENV_ROOT=/usr/local/pyenv/
export PATH="/usr/local/pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
也在root
用户中设置
$ sudo cat /root/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export PYENV_ROOT=/usr/local/pyenv/
export PATH="/usr/local/pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
我正在使用centos
$ cat /etc/issue
CentOS release 6.9 (Final)
解决方案
$ export PYENV_ROOT=/usr/local/pyenv/
$ sudo /usr/local/pyenv/bin/pyenv versions
这不起作用,因为PYENV_ROOT
不会传递给 sudo 中的环境。尝试这个:
$ sudo PYENV_ROOT=/usr/local/pyenv/ /usr/local/pyenv/bin/pyenv versions
或这个:
$ export PYENV_ROOT=/usr/local/pyenv/
$ sudo -E /usr/local/pyenv/bin/pyenv versions
-E
将使环境变量传递给 pyenv。在手册页中sudo
:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to
preserve the environment.
--preserve-env=list
Indicates to the security policy that the user wishes to add the comma-separated list of environment variables to those preserved from the user's environment. The security policy may
return an error if the user does not have permission to preserve the environment.
.bash_profile
in root 不起作用,因为在sudo
这种情况下不会加载它。如果您更喜欢将配置写入.bash_profile
.
推荐阅读
- amazon-web-services - AWS CloudFormation:对子网的引用导致错误
- python - 如何让我的不和谐机器人从文件中读取并将其粘贴到不和谐聊天命令中?
- reactjs - redux 标准化状态:byId 和 allIds 模式
- c# - 如何将两个剑道过滤器组件用于嵌套剑道网格(层次结构)
- c# - X509Certificate2 的 .pem 私钥
- xquery - xquery在病历号上的基本连接失败
- python - 如何使用记录列表将域应用于 Odoo 中的 Many2One 字段
- javascript - 我可以从 JavaScript 中的字符串构建关联数组的索引吗?
- python - 如何将在多行中找到的数字存储在 csv 文件中
- sql - 在 Excel VBA 中使用 SQL 查找 PGSQL 表中所做的更改