'Pyenv not showing as a command

When I write pyenv It says

Command 'pyenv' not found, did you mean:
command 'p7env' from deb libnss3-tools
Try: sudo apt install <deb name>

I know this is very common and it is something with the path. I have tried everything in all different files such as bashrc, bash_profile, zshrc etc. What I currently have is in my "bashrc" file:

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

When I write bash and then reload the terminal it works, but I cannot change the python version.

I am using a Linux Debian distribution and pyenv version 1.2.27



Solution 1:[1]

Bash sources ~/.bashrc only for interactive non-login shells. So, in an interactive login shell, before you type bash to open an interactive non-login shell, your ~/.bashrc file will not have been sourced yet. You can fix this by adding the following to your ~/.bash_profile file:

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

Solution 2:[2]

For me, it worked like that (in the end of .bashrc):

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
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 Marlon Richert
Solution 2 John Doe