激活虚拟环境时 pyenv 不再正确设置路径

2024-02-23

我已经使用 pyenv 近两年了,在 X11 模式下运行 RHEL 8.3(Linux 内核 4.18)和 Gnome 3.32.2 的系统上没有出现任何问题。我主要使用 Fish shell,但偶尔也会使用 bash,到目前为止,两者都可以很好地与 pyenv 配合使用。然而,运行后pyenv update大约 24 小时前,使用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

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 -)"

还有一些观察结果:

  1. 我发现即使我有~/.profile,当我登录桌面环境时,它永远不会被获取/运行。
  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没有什么区别。

最后,即使在激活 pyenv 创建的虚拟环境后,我仍然无法访问其中的内容。

我该如何解决这个问题?谢谢。


OS: ubuntu 18.04

我更新了pyenv by

pyenv update 

它开始显示这个警告

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

and pyenv不再正确设置路径

FIX

我的里面有这些行~/.bashrc . So, 删除/评论这些行如果你有~/.bashrc

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

将这些行添加到~/.profile before采购~/.bashrc

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

来源简介

source ~/.profile
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

激活虚拟环境时 pyenv 不再正确设置路径 的相关文章

随机推荐