问题描述
我已经使用 pyenv 近两年了,在运行 RHEL 8.3(Linux 内核 4.18)和 X11 模式下的 Gnome 3.32.2 的系统上没有出现任何问题。我主要使用鱼壳,但偶尔也会使用 bash,直到现在都可以与 pyenv 一起使用。但是,在大约 24 小时前运行 pyenv update
后,使用 pyenv activate
命令激活我创建的虚拟环境之一不再设置路径以使用我在该虚拟环境中安装的内容。
当我开始终端会话时,我看到一条新消息:
WARNING: `pyenv init -` no longer sets PATH.
Run `pyenv init` to see the necessary changes to make to your configuration.
所以我运行了 pyenv init
它告诉我:
# Add pyenv executable to PATH by adding
# the following to ~/.profile:
set -Ux PYENV_ROOT $HOME/.pyenv
set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths
# Load pyenv automatically by appending
# the following to ~/.config/fish/config.fish:
pyenv init - | source
# and the following to ~/.profile:
pyenv init --path | source
# If your ~/.profile sources ~/.config/fish/config.fish,# the lines should be inserted before the part
# that does that.
# Make sure to restart your entire logon session
# for changes to ~/.profile to take effect.
我很确定我已经拥有了上述所有内容。这是我的~/.profile
:
set -Ux PYENV_ROOT $HOME/.pyenv
set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths
pyenv init --path | source
这是我的~/.config/fish/config.fish
:
# Set default editor
set -gx EDITOR nano
# Set Junest path
set PATH /home/[username]/.local/share/junest/bin $PATH
# Set pyenv root directory
set PYENV_ROOT $HOME/.pyenv
# Add pyenv and local bin to $PATH
set PATH $PYENV_ROOT/bin /home/[username]/.local/bin $PATH
# Add pyenv init to shell to enable shims and autocompletion
# Note the command `pyenv init` will tell you to add this line for fish
status --is-interactive; and source (pyenv init -|psub)
pyenv init - | source
我的~/.bashrc
:
# Source global deFinitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific environment
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
export PATH
# Uncomment the following line if you don't like systemctl's auto-paging featur$
# export SYstemD_PAGER=
# User specific aliases and functions
# Load pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
更多观察:
- 我发现即使我有
~/.profile
,当我登录到我的桌面环境时它也永远不会被获取/运行。 - 将
set -Ux PYENV_ROOT $HOME/.pyenv
和set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths
放在~/.profile
或~/.config/fish/config.fish
中没有区别。
最后,即使激活了 pyenv 创建的虚拟环境,我仍然无法访问其中的内容。
我该如何解决这个问题?谢谢。
解决方法
操作系统:ubuntu 18.04
我更新了pyenv
pyenv update
它开始显示这个警告
WARNING: `pyenv init -` no longer sets PATH.
Run `pyenv init` to see the necessary changes to make to your configuration.
和 pyenv
不再正确设置路径
修复
我的 ~/.bashrc
中有这些行。因此,如果您在 ~/.bashrc
export PATH="/home/yogi/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
添加这些行之前采购~/.bashrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
来源简介
source ~/.profile
,
消息是错误的。 ~/.profile 用于兼容 posix 的 shell,而 fish 不是,因此它不会读取它。这应该报告为 pyenv 中的错误。
现在,您已经将代码添加到 config.fish 中的 $PATH,因此您似乎不需要采取进一步的行动,警告不适用于您。
你的 ~/.profile 是鱼代码,它与可以读取它的 shell 不兼容,我建议删除它。
如果你还没有所有必要的东西:
奇怪的是,实际的代码与鱼兼容(pyenv init --path
除外,它打印 posix 代码。我建议跳过它)。由于它建议通过 set -U
使用通用变量,并且这些变量会持续存在,因此您只需交互式运行一次 set -U
:
set -Ux PYENV_ROOT $HOME/.pyenv
set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths
您不想想在 config.fish 中添加这些。 Fish 保持通用变量,并且这个添加到 $fish_user_paths,所以每次你打开一条鱼时它都会添加一个组件,这最终会让你在其中留下数百个元素并减慢鱼的速度。
或者自己在 config.fish 中将 $PYENV_ROOT/bin 添加到 $PATH 中,就像您已经在执行的 $PATH 添加一样:
# Set pyenv root directory
set -gx PYENV_ROOT $HOME/.pyenv
# (note that this must now come later because it uses $PYENV_ROOT)
set -gx PATH /home/[username]/.local/share/junest/bin $PYENV_ROOT/bin $PATH
(或使用 fish_add_path
,在fish 3.2 中发货 - fish_add_path /home/[username]/.local/share/junest/bin $PYENV_ROOT/bin
- 这将确保不会多次添加)
保留 pyenv init - | source
(最终效果与 source (pyenv init -|psub)
相同,没有无用的临时文件,因此是首选)
对于那些已经解决了这个问题并且正在使用鱼以外的东西的人,我也尝试按照 pyenv -init
给出的说明进行操作,但没有成功。像@jmunsch 一样,我有 Ubuntu 20.04 和 bash。但是,似乎 ~/.profile
没有被读取,或者我的 bash 配置中的某些内容在 ~/.profile
运行之前覆盖了相关的 pyenv -init
设置。不知道这可能是什么,但在有人问之前:
- 是的,
~/.profile
更改设置在 source~/.bashrc
行之前 - 不,我不使用
~/.bash_profile
或~/.bash_login
这是我在~/.bashrc
中ALL所做的:
export PYENV_ROOT=$HOME/.pyenv
export PATH=$PYENV_ROOT/bin:$PATH
# <Other commands not relevant to pyenv - jump straight to evals if you like>
# .
# .
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
我还没有对 pyenv
进行详尽的测试,但警告已经消失,它似乎运行正常。
只需将 eval "$(pyenv init -)"
文件中的 ~/.bashrc
行替换为 eval "$(pyenv init --path)"
。
请参考这个问题:https://github.com/pyenv/pyenv/issues/1906
,对于 Mac 和 fish,将其添加到 ~/.config/fish/config.fish
:
set PYENV_ROOT $HOME/.pyenv
set -x PATH $PYENV_ROOT/shims $PATH
set -x PATH $PYENV_ROOT/bin $PATH
if command -v pyenv 1>/dev/null 2>&1
pyenv init - | source
end
,
Ubuntu 20.04 / bash
-
从
中删除 pyenv init 的任何旧行~/.bashrc
、~/.profile
-
在 bashrc 底部添加
eval "$(pyenv init -)"
: -
将
eval "$(pyenv init --path)
添加到~/.profile
BEFORE .bashrc 来源。