'WARNING: `pyenv init -` no longer sets PATH when starting the terminal window

Goal: I am trying to install the "pyenv" on my Linux machine with the help of this article "https://realpython.com/intro-to-pyenv/"

Expected Result: according the article pyenv should add to the "load path" of my Linux machine.

Actual Result: pyenv doesnt add to the load path and I have to manually add to the .bashrc file.

Error Messages: Actually I am not seeing any error messages for now. When I close my terminal window and open new one ; each time my terminal window opens up with the below message.

WARNING: `pyenv init -` no longer sets PATH.
Run `pyenv init` to see the necessary changes to make to your configuration.
[centos@localhost ~]$ 

What I have done: I have searched through the SO for answers and I found my issue with some resolutions. but they didn't work for me as expected. I have added the below lines to the .bashrc file of my user.

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

Mind you that, even though this warning comes every time when I add 'pyenv' command to the terminal it shows me with the valid result.

for the references below is my .bash_profile and .bashrc files contents.


.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

#JAVA_HOME=/data/programs/jdk1.8.0_221
#JAVA_HOME=/data/programs/jdk-13.0.2
#JAVA_HOME=/data/programs/jdk1.7.0_80
JAVA_HOME=/data/programs/jdk-11.0.8
#JAVA_HOME=/data/programs/jdk-14.0.1
M2_HOME=/data/programs/apache-maven-3.6.1
JRE_HOME=$JAVA_HOME


export PATH JAVA_HOME M2_HOME JRE_HOME
export PATH=$JAVA_HOME/bin:$M2_HOME/bin::$PATH

export PATH

Also below is my .bashrc file contents.

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

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

Environment: Centos 7

I want remove this error when I'm opening a terminal session every time. How do I resolve this ?



Solution 1:[1]

pyenv is upgraded to 2.0 and the init script is changed. Read from the official homepage but not some random article on the web.

Check README.md in pyenv on GitHub

Fix for your problem.

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

NOTE: code above is not the whole pyenv init script, it only answers this very question. If you're setting up pyenv from the beginning, check pyenv's repo on Github for detail.

Solution 2:[2]

Just replace the line eval "$(pyenv init -)" from your ~/.bashrc file to eval "$(pyenv init --path)".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Douglas Tbt