8

I use pyenv to manage my Python environments and I get the following when simply running bash.

$ bash
pyenv: bash: command not found

I was trying to troubleshoot why pipenv shell failed with the above error, which is how I found out even bash wasn't working. I tried updating pipenv via brew and ran pyenv rehash to regenerate the shims. And bash is definitely present.

$ which bash
/bin/bash

I expected that if pyenv doesn't find a command, the subsequent paths specified by the PATH environment variable will be searched. Interestingly if I execute some non-existant command I don't get a pyenv error.

$ someboguscommand
-bash: someboguscommand: command not found

This suggests to me that pyenv doesn't even search for a matching command in this case and the subsequent paths in PATH are searched, so there must be some special handling with bash.

6
  • What does type bash say? Commented Sep 9, 2019 at 16:48
  • 2
    This suggests that the problem is with a command in your init files, such as .bashrc or .bash_profile. You can run bash -x to show a debug trace of what's going on, and where it starts to fail. Running bash by itself probably worked in spite of the error, and is only showing a warning about a failing pyenv command in your .bashrc or .bash_profile while otherwise giving you a working shell. Commented Sep 9, 2019 at 17:02
  • 2
    Better, I'd suggest PS4=':$BASHPID:${BASH_SOURCE##*/}:$LINENO+' bash -x, to log a process ID, source file and line number with each command in the trace log. Compare the BASHPID in those logs with the one in your starting shell and you have a conclusive answer as to whether the error is in- or out-of-process. Commented Sep 9, 2019 at 17:04
  • 1
    BTW, at the risk of drifting out of advice into advocacy, personally, I'm much happier using Nix for managing development environments -- which lets you control not just which Python modules are in-scope for each shell or project, but also versions of other executables and libraries; meaning you can have, say, bash 5 in one environment, and bash 3.2 in another; or a Python built against one version of zlib or sqlite in one, and a different version in another; etc -- likewise, it supports managing Ruby/Node/Haskell/etc. compilers/interpreters/libraries. Commented Sep 9, 2019 at 17:09
  • 1
    I would start by looking at my .profile, .bashrc and similar files. The init code for pyenv is in their and seems to be broken. Maybe remove that and setup pyenv again? Commented Sep 9, 2019 at 18:13

3 Answers 3

13

I had this issue when setting up Python 3.8 on CentOS using Pyenv.

I was running into the error below when I run pyenv install 3.8.2:

pyenv: bash: command not found

Here's how I solved it:

The issue was pyenv was not added to the load path for my profile.

All I had to do was to do the following:

Open the .bashrc file in the home directory of my user:

sudo nano ~/.bashrc

Next, add the following add the bottom of the file and save:

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

Finally, restart your terminal or run the command below to load the newly added paths into your current shell/terminal session:

exec "$SHELL"

Now when you run the command pyenv install 3.8.2 it should work fine.

Resources: Managing Multiple Python Versions With pyenv

That's all.

I hope this helps

Sign up to request clarification or add additional context in comments.

Comments

1

The issue was that I had the following line in my .bashrc, which was being invoked when running bash. It's a line that I no longer need:

. virtualenvwrapper.sh

This was in turn invoking pyenv's virtualwrapper shim:

$ which virtualenvwrapper.sh
/Users/greg/.pyenv/shims/virtualenvwrapper.sh

That's what caused the failure. I was able to identify this by running a debug trace with bash:

$ bash -x
+ . virtualenvwrapper.sh
++ set -e
++ '[' -n '' ']'
++ program=bash
++ [[ bash = \p\y\t\h\o\n* ]]
++ export PYENV_ROOT=/Users/greg/.pyenv
++ PYENV_ROOT=/Users/greg/.pyenv
++ exec /usr/local/Cellar/pyenv/1.2.13_1/libexec/pyenv exec bash
pyenv: bash: command not found

Thank you for the useful comments "that other guy", Charles Duffy, and rje!

Comments

0

For me the error was:

bash: pyenv: command not found.

  1. I fixed this error just by creating the .pyenv file inside the C:\Users\<username>\

  2. I found the another solution on GitHub:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc

echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.