pyenv-installer icon indicating copy to clipboard operation
pyenv-installer copied to clipboard

Pyenv installer does not add to path

Open sabotagebeats opened this issue 3 years ago • 46 comments

Pyenv is not found after installer is ran. After adding code to .profile and .bashrc it is also not found. Finally after manually adding modified code from github, I get error code when I exit bash. This installer script does not function properly.

https://github.com/pyenv/pyenv/issues/1994

sabotagebeats avatar Jun 28 '21 19:06 sabotagebeats

reinstalled clean ubuntu 20.04 LTS on wsl2, installed dependencies, ran script,

$ pyenv
Command 'pyenv' not found

sabotagebeats avatar Jun 28 '21 19:06 sabotagebeats

according to uninstall instructions https://github.com/pyenv/pyenv-installer/blob/master/README.rst#uninstall the installer should automatically modify the .bashrc and it is not.

sabotagebeats avatar Jun 28 '21 19:06 sabotagebeats

when installer script runs, it shows the following output.

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


# (The below instructions are intended for common
# shell setups. See the README for more guidance
# if they don't apply and/or don't work for you.)

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

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

# If your ~/.profile sources ~/.bashrc,
# the lines need to be inserted before the part
# that does that. See the README for another option.

# If you have ~/.bash_profile, make sure that it
# also executes the above lines -- e.g. by
# copying them there or by sourcing ~/.profile

# Load pyenv into the shell by adding
# the following to ~/.bashrc:

eval "$(pyenv init -)"

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

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

eval "$(pyenv virtualenv-init -)"

sabotagebeats avatar Jun 28 '21 19:06 sabotagebeats

after following those instructions and restarting the terminal, I'm able to use pyenv but when I exit the terminal I get the error The terminal process "bash" terminated with exit code: 1. as mentioned here: https://github.com/pyenv/pyenv/issues/1994

sabotagebeats avatar Jun 28 '21 19:06 sabotagebeats

Same issue.

connerxyz avatar Jun 29 '21 17:06 connerxyz

@connerxyz were you able to fix it by adding the code to your .profile and .bashrc or did you still have the exit error code 1 issue? Are you using vscode with wsl2 ubuntu 20.04 LTS also?

sabotagebeats avatar Jun 29 '21 18:06 sabotagebeats

have a look at the first solution in the link below

https://github.com/pyenv/pyenv-installer/issues/103

cchanzl avatar Jul 08 '21 08:07 cchanzl

@cchanzl I tried the instructions there but still have the error code 1 https://github.com/pyenv/pyenv-installer/issues/103#issuecomment-800984446

The terminal process "bash" terminated with exit code: 1.

sabotagebeats avatar Jul 12 '21 23:07 sabotagebeats

more context: https://github.com/ApeWorX/ape/issues/105

sabotagebeats avatar Jul 26 '21 22:07 sabotagebeats

this should be a part of the pyenv installer script to ask the user if the user would like to add the required lines to the ~/.bashrc

sabotagebeats avatar Jul 26 '21 22:07 sabotagebeats

I hit the same issue today.

I think this happened with pyenv 2.0+ upgrade (first release in may 23). They changed the bashrc script to:

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

Second line was eval "$(pyenv init -)".

https://github.com/pyenv/pyenv/blob/master/README.md#basic-github-checkout

iurisilvio avatar Aug 24 '21 21:08 iurisilvio

This still looks broken for me?

The workaround I used since there was only one file was sudo ln -s "${HOME}/.pyenv/bin/pyenv" "/usr/local/bin/." which got it working.

VikashKothary avatar Sep 02 '21 15:09 VikashKothary

Same issue today. Installed with script on ubuntu 20.04, restarted shell and still

$pyenv
Command 'pyenv' not found

fixed by manually adding to ~/.bashrc the lines:

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

and then restarting the shell with exec $SHELL.

EmanueleGallone avatar Sep 18 '21 12:09 EmanueleGallone

This still looks broken for me?

Did it ever work? From what I see in the code, Pyenv-Installer didn't ever edit shell startup files automatically.

native-api avatar Oct 18 '21 22:10 native-api

The script change worked for me.

iurisilvio avatar Oct 18 '21 22:10 iurisilvio

fixed by manually adding to ~/.bashrc the lines:

Check Pyenv's and Pyenv-Virtualenv's README for the proper setup. With the code you gave, pyenv activate won't work.

E.g. for Ubuntu, that'll be (as of this writing):

sed -Ei -e '/^([^#]|$)/ {a \
export PYENV_ROOT="$HOME/.pyenv"
a \
export PATH="$PYENV_ROOT/bin:$PATH"
a \
' -e ':a' -e '$!{n;ba};}' ~/.profile
echo 'eval "$(pyenv init --path)"' >>~/.profile

echo 'eval "$(pyenv init -)"' >> ~/.bashrc

echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc

Then restart your login session.

native-api avatar Oct 18 '21 22:10 native-api

After installing the follow message appears

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


# See the README for instructions on how to set up
# your shell environment for Pyenv.

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

eval "$(pyenv virtualenv-init -)"

Still fail to find pyenv after add "eval $(pyenv virtualenv-init -)" to .bashrc or .profile

I had to manually add to .bashrc

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

thiagola92 avatar Oct 19 '21 14:10 thiagola92

@anton-petrov it seems like the issue should be reopened: as it stands, the README for this project is incorrect, pyenv command won't work by itself after the installation

kyegupov avatar Nov 02 '21 13:11 kyegupov

Had the same issue w/ Mac OS X 10.15.7 using zsh. Had to manually add the shim path to .zshrc

Running % pyenv doctor would say all was good:

 % pyenv doctor
Cloning /Users/jheasly/.pyenv/plugins/pyenv-doctor/bin/.....
Installing python-pyenv-doctor...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed python-pyenv-doctor to /var/folders/tq/1wdf1n1n75xfr3swdjtpq6jm0000gn/T/pyenv-doctor.20211103162934.85601/prefix

Congratulations! You are ready to build pythons!
 % 

... but the pyenv python wouldn't be found. The system python is what would launch when I did % python on the command line after setting a system python via pyenv. Once I manually added the shim to .zshrc, all worked.

p.s.: Also had to add

export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@3/include"

to .zshrc for % pyenv doctor to work.

jheasly avatar Nov 03 '21 21:11 jheasly

https://github.com/pyenv/pyenv/issues/2148

sabotagebeats avatar Nov 09 '21 18:11 sabotagebeats

After installing the follow message appears

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


# See the README for instructions on how to set up
# your shell environment for Pyenv.

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

eval "$(pyenv virtualenv-init -)"

Still fail to find pyenv after add "eval $(pyenv virtualenv-init -)" to .bashrc or .profile

I had to manually add to .bashrc

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

I tried to manually add this and I get this error:

Failed to activate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

sabotagebeats avatar Nov 09 '21 18:11 sabotagebeats

I was able to get it to activate with this

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

however it still is broken when trying to install it uses the wrong path

 Running setup.py develop for eth-ape
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/sabotage/ape/ape/setup.py'"'"'; __file__='"'"'/home/sabotage/ape/ape/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps --user --prefix=
         cwd: /home/sabotage/ape/ape/
    Complete output (18 lines):
    running develop
    WARNING: The user site-packages directory is disabled.
    error: can't create or remove files in install directory
    
    The following error occurred while trying to add or remove files in the
    installation directory:
    
        [Errno 2] No such file or directory: '/usr/lib/python3.8/site-packages/test-easy-install-14112.write-test'
    
    The installation directory you specified (via --install-dir, --prefix, or
    the distutils default setting) was:
    
        /usr/lib/python3.8/site-packages/
    
    This directory does not currently exist.  Please create it and try again, or
    choose a different installation directory (using the -d or --install-dir
    option).
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/sabotage/ape/ape/setup.py'"'"'; __file__='"'"'/home/sabotage/ape/ape/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps --user --prefix= Check the logs for full command output.

sabotagebeats avatar Nov 09 '21 18:11 sabotagebeats

https://github.com/ApeWorX/ape/issues/222

sabotagebeats avatar Nov 09 '21 18:11 sabotagebeats

tried these commands and it didn't resolve the issue

rm -rf ~/.pyenv
sudo apt install zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev tk-dev libssl-dev llvm \
libncurses5-dev libncursesw5-dev xz-utils libffi-dev liblzma-dev python-openssl
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
pyenv update 
pyenv install 3.8.12
pyenv virtualenv 3.8.12 apeworx

sabotagebeats avatar Nov 17 '21 20:11 sabotagebeats

changing my ~/.bashrc to this fixed the issue

# So pyenv gets recognized
export PATH="$PATH:$HOME/.pyenv/bin"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

sabotagebeats avatar Nov 17 '21 20:11 sabotagebeats

closing as I have gotten this to work. please reopen if anyone still faces issue.

sabotagebeats avatar Nov 17 '21 20:11 sabotagebeats

Can we get a re-open on this?

Per @sabotagebeats' comment you can get pyenv to work by manually appending to ~/.bashrc, but:

a. That is not mentioned in the docs (see below), and moreover: b. Surely is something this installer script can/should do automatically?


Example of following the docs:

$ docker run -it mcr.microsoft.com/vscode/devcontainers/base:0-focal bash                   
root ➜ / $ curl https://pyenv.run | bash

[...]

Unpacking objects: 100% (10/10), 2.92 KiB | 597.00 KiB/s, done.

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

# See the README for instructions on how to set up
# your shell environment for Pyenv.

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

eval "$(pyenv virtualenv-init -)"

⬆️ this is already a red flag, but the docs only say to exec $SHELL:

root ➜ / $ exec $SHELL
root ➜ / $ pyenv
bash: pyenv: command not found

This leaves the user having to go back to the pyenv README (which doesn't make any mention of needed to manually append to ~/.bashrc in the Automatic installer section).

davetapley avatar Nov 19 '21 19:11 davetapley

Here's what happens when you follow the directions in the README on Ubuntu 21.10:

$ sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
  libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev \
  liblzma-dev python3-openssl git && echo 'Success'
Success

$ curl https://pyenv.run | bash
[snip]
WARNING: seems you still have not added 'pyenv' to the load path.

# See the README for instructions on how to set up
# your shell environment for Pyenv.

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

eval "$(pyenv virtualenv-init -)"

$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
$ exec $SHELL
$ pyenv
Command 'pyenv' not found, did you mean:
  command 'p7env' from deb libnss3-tools (2:3.61-1ubuntu2)

Similar problem when doing the same on Arch.

This was solved by copying and pasting the following into my ~/.bashrc from the "Uninstall" section of the README:

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

I agree with @davetapley's points.

alexdelorenzo avatar Dec 01 '21 04:12 alexdelorenzo

b. Surely is something this installer script can/should do automatically?

Came here to suggest that the install script should setup the entire environment so you can start using pyenv immediately.

211217613 avatar Dec 07 '21 22:12 211217613

I'm taking a look at at nvms installer and it automatically modifies your shell environment via https://github.com/nvm-sh/nvm/blob/81fc05684de8b0b13aed401de64733e1d5d23a9a/install.sh#L345 and then adds the required lines to your shell config file here

the pyenv-installer should do something similar while also leaving an option of not modifying your shell config files if you already do that on your own.

For example I have separate files that my shell config loads if the binary is present.

211217613 avatar Dec 07 '21 22:12 211217613