18

I've been using pyenv for almost two years with no problems on my system running RHEL 8.3 (Linux kernel 4.18) with Gnome 3.32.2 in X11 mode. I primarily use the fish shell but also occasionally bash, both worked fine with pyenv until now. However, after running pyenv update about 24 hours ago, using the pyenv activate command to activate one of my created virtual environments no longer sets the path to use what I've installed in that virtual environment.

When I start a terminal session, I see a new message saying:

WARNING: `pyenv init -` no longer sets PATH.
Run `pyenv init` to see the necessary changes to make to your configuration.

So I ran pyenv init which told me:

# 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.

I'm pretty sure I already have all of the above. Here's my ~/.profile:

set -Ux PYENV_ROOT $HOME/.pyenv
set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths
pyenv init --path | source

Here's my ~/.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

My ~/.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 -)"

A few more observations:

  1. I discovered that even though I have ~/.profile, it is never sourced/run when I log into my desktop environment.
  2. Putting set -Ux PYENV_ROOT $HOME/.pyenv and set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths in ~/.profile or ~/.config/fish/config.fish doesn't make a difference.

In the end, even after activating a pyenv-created virtual environment, I still don't have access to what's in it.

How can I troubleshoot this? Thank you.

4

5 回答 5

15

操作系统: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 -)"

在采购~/.profile 之前添加这些行~/.bashrc

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

源配置文件

source ~/.profile
于 2021-05-31T20:27:43.113 回答
6

消息是错误的。~/.profile 适用于与 posix 兼容的 shell,而 fish 不是,因此它不会读取它。这应该报告为 pyenv 中的错误。

现在,您已经在 config.fish 中添加了要添加到 $PATH 的代码,因此您似乎不需要采取进一步的行动,警告不适用于您。

您的 ~/.profile 是鱼代码,它与将读取它的 shell 不兼容,我建议将其删除。


如果您还没有所有必要的位:

奇怪的是,实际代码是与鱼兼容的(打印posix代码的除外pyenv init --path。我建议跳过它)。由于它建议使用通用变量 via 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)没有无用的临时文件一样,所以它是首选)

于 2021-05-10T19:05:07.140 回答
5

只需将文件中的行eval "$(pyenv init -)"替换~/.bashrceval "$(pyenv init --path)".

请参考这个问题:https ://github.com/pyenv/pyenv/issues/1906

于 2021-06-01T12:44:58.597 回答
4

对于 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
于 2021-06-28T21:41:24.613 回答
2

对于那些已经解决这个问题并且使用鱼以外的东西的人,我也尝试按照pyenv -init没有成功的指示进行操作。像@jmunsch 一样,我有 Ubuntu 20.04 和 bash。但是,它似乎~/.profile没有被读取,或者我的 bash 配置中的某些内容在运行~/.profile之前覆盖了相关设置pyenv -init。不知道这可能是什么,但在有人问之前:

  1. 是的,~/.profile更改是在来源行之前设置的~/.bashrc
  2. 不,我不使用~/.bash_profile~/.bash_login

这就是我所做的,全部~/.bashrc

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彻底测试过,但警告已经消失,它似乎运行正常。

于 2021-05-27T22:20:04.663 回答