Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The instructions for adding pyenv to the load path result in command not found errors #1911

Closed
10 tasks done
Jackenmen opened this issue May 9, 2021 · 2 comments · Fixed by #1912
Closed
10 tasks done

Comments

@Jackenmen
Copy link

Prerequisite

  • Make sure your problem is not listed in the common build problems.
  • Make sure no duplicated issue has already been reported in the pyenv issues. You should look for closed issues, too.
  • Make sure you are not asking us to help solving your specific issue.
    • GitHub issues is opened mainly for development purposes. If you want to ask someone to help solving your problem, go to some community site like Gitter, StackOverflow, etc.
  • Make sure your problem is not derived from packaging (e.g. Homebrew).
    • Please refer to the package documentation for the installation issues, etc.
  • Make sure your problem is not derived from plugins.
    • This repository is maintaining pyenv and the default python-build plugin only. Please refrain from reporting issues of other plugins here.

Description

  • Platform information (e.g. Ubuntu Linux 16.04): Debian Buster, same should apply to most if not all popular distros
  • OS architecture (e.g. amd64): amd64
  • pyenv version: current master (f0a8e72)
  • Python version: N/A
  • C Compiler information (e.g. gcc 7.3): N/A

This is what is currently shown after running pyenv-installer (most of this message is coming from output of pyenv init so this repo should be appropriate):

WARNING: seems you still have not added 'pyenv' to the load path.

# Add pyenv executable to PATH by adding
# the following to ~/.profile:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"

# Load pyenv automatically by appending
# the following to ~/.bashrc:

eval "$(pyenv init -)"

# and the following to ~/.profile:

eval "$(pyenv init --path)"

# Make sure to restart your entire logon session
# for changes to ~/.profile to take effect.

# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:

eval "$(pyenv virtualenv-init -)"

So by following this, I end up with these contents appended to the end of the listed files:

  • ~/.profile
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
  • ~/.bashrc
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

This will result in the new bash shells giving this output on startup of interactive login shell (meaning that the commands from .bashrc failed to run):

-bash: pyenv: command not found
-bash: pyenv: command not found

This is because in the default contents of ~/.profile (in case of Debian-based distros), ~/.bash_profile (in case of RHEL-based distros), or /etc/profile (in case of openSUSE) file, ~/.bashrc is sourced at the beginning of it and so when user appends these commands at the end, it doesn't work because .bashrc pretty much always runs before .profile.

Additional context

pyenv/pyenv-virtualenv#383 and #1909 address somewhat similar issues but neither of the bug fixes are fixing what I'm reporting in this issue.

@native-api
Copy link
Member

native-api commented May 9, 2021

Okay, I see.

This can only be seen in text sessions -- so I couldn't see it in a GUI session.
(Of course, the errors messages still happen -- but they are hidden from the user and do not affect interactive shells run in windows, even if they are login shells.)

So, all we need to do is move the code in ~/.profile to before the chunk that sources ~/.bashrc.
@jack1142 , could you check if that fixes the problem?

  • I've checked that we cannot just move all the code to ~/.bashrc and detect a login shell -- OSX ~/.profile does not source it (neither it, nor ~/.zshrc).

@dausruddin
Copy link

I am going to add a note here in case anyone stumbled upon the same issue like mine.
I had the same error like in OP and it took me a while to figure it out.

bash: pyenv: command not found

I was installing pyenv using pyenv-installer on my Arch Linux Desktop. Upon reading the last step where I need to paste mentioned lines into ~/.profile, I found out that I don't have the file in my $HOME. So I created one. It wouldn't work at all, but sourcing the file worked.

So after digging, I found this. Turned out if you have ~/.bash_profile or ~/.bash_login, bash wouldn't load ~/.profile. I pasted required lines into ~/.bash_profile instead, restarted my session, and it is finally working.

Some distros might auto load ~/.profile, but in my Arch, it didn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants