Python: How to fix "pyenv: bash: command not found"
Asked Answered
I

3

7

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.

Incredible answered 9/9, 2019 at 16:47 Comment(6)
What does type bash say?Dubuffet
$ type bash bash is hashed (/bin/bash)Incredible
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.Dubuffet
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.Springhouse
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.Springhouse
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?Ruyle
I
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!

Incredible answered 10/9, 2019 at 0:52 Comment(0)
O
9

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

Okajima answered 3/2, 2021 at 22:45 Comment(0)
I
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!

Incredible answered 10/9, 2019 at 0:52 Comment(0)
Z
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
Zita answered 19/6 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.