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

zsh: command not found: pyenv #233

Closed
rghamilton3 opened this issue Sep 10, 2017 · 36 comments
Closed

zsh: command not found: pyenv #233

rghamilton3 opened this issue Sep 10, 2017 · 36 comments

Comments

@rghamilton3
Copy link

My .zshenv contains

export PYENV_ROOT="$HOME"/.pyenv
export PATH="$PYENV_ROOT"/bin:"$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

which works fine, however, if I simply add
eval "$(pyenv virtualenv-init -)"
I keep receiving the message
zsh: command not found: pyenv

Pyenv and pyenv-virtualenv work perfectly fine and if I enter exec "$SHELL" the message goes away until I restart the terminal so I'm sure what the issue is.

I'm running Arch Linux, Zsh 5.4.2-1, tmux 2.5-3, termite 12-2, and the master branch of both pyenv and pyenv-virtualenv pulled today.

@yyuu
Copy link
Collaborator

yyuu commented Sep 11, 2017

It eval "$(pyenv virtualenv-init -)" is showing errors like "zsh: command not found: pyenv", it indicates that pyenv-virtualenv-init was called before pyenv-init. Since pyenv-virtualenv is heavily depending on pyenv, it needs to be initialized after pyenv has initialized.

Pasting your full zsh configurations (regard to pyenv/pyenv-virtualenv) here could help further investigation.

@dogfish182
Copy link

dogfish182 commented Feb 4, 2018

I have same issue

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi
eval "$(pyenv virtualenv-init -)"

entire contents of my .zshenv and copy pasting it to a loaded shell works as intented.

just ditching my .zshenv file and pasting its contents into .zshrc works as intended as well.

I'm using ohmyzsh if that makes any diff.

@dichen001
Copy link

I have the same issue.
My ~/.zshenv file:

export PYENV_ROOT="$HOME"/.pyenv
export PATH="$PYENV_ROOT"/bin:"$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi
eval "$(pyenv virtualenv-init -)"

@pvarin
Copy link

pvarin commented Oct 4, 2018

My guess is that pyenv is being installed in a location that zsh doesn't use by default (like /usr/local/bin). You probably have a line at the top of your .zshrc that looks like export PATH=$HOME/bin:/usr/local/bin:$PATH. Moving that line to the top of your .zshenv might fix the problem for you.

@laike9m
Copy link

laike9m commented Dec 9, 2018

My guess is that pyenv is being installed in a location that zsh doesn't use by default (like /usr/local/bin). You probably have a line at the top of your .zshrc that looks like export PATH=$HOME/bin:/usr/local/bin:$PATH. Moving that line to the top of your .zshenv might fix the problem for you.

Works for me, thanks 😄

@ghost
Copy link

ghost commented Dec 23, 2018

Some update ?

@sean-smith
Copy link

I had this issue, after following https://github.com/pyenv/pyenv-installer

I changed my ~/.zshrc from:

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

To

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

@beizhengren
Copy link

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

nice

sean-smith added a commit to sean-smith/pyenv-installer that referenced this issue May 14, 2019
This is breaking some customers, who just copy paste these lines into their `*rc` file

See pyenv/pyenv-virtualenv#233 (comment)
sean-smith added a commit to sean-smith/pyenv-installer that referenced this issue May 14, 2019
This is breaking some customers, who just copy paste these lines into their `*rc` file

See pyenv/pyenv-virtualenv#233 (comment)
@sean-smith
Copy link

Opened a PR to change this pyenv/pyenv-installer#86

@NguyenThienLy
Copy link

I had this issue, after following https://github.com/pyenv/pyenv-installer

I changed my ~/.zshrc from:

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

To

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

Cool, tk you verry much

@carusyte
Copy link

carusyte commented Jul 3, 2020

The above fix didn't work for me though. I used the following block in ~/.zshrc instead:

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
  eval "$(pyenv virtualenv-init -)"
fi

rahulraj1255 pushed a commit to rahulraj1255/training_ansible that referenced this issue Nov 2, 2020
author Rahul <rahul@Rahuls-MacBook-Pro.local> 1604040420 +0800
committer Rahul <rahul@Rahuls-MacBook-Pro.local> 1604278976 +0800

parent 772a5db
author Rahul <rahul@Rahuls-MacBook-Pro.local> 1604040420 +0800
committer Rahul <rahul@Rahuls-MacBook-Pro.local> 1604278973 +0800

parent 772a5db
author Rahul <rahul@Rahuls-MacBook-Pro.local> 1604040420 +0800
committer Rahul <rahul@Rahuls-MacBook-Pro.local> 1604278971 +0800

parent 772a5db
author Rahul <rahul@Rahuls-MacBook-Pro.local> 1604040420 +0800
committer Rahul <rahul@Rahuls-MacBook-Pro.local> 1604278963 +0800

parent 772a5db
author Rahul <rahul@Rahuls-MacBook-Pro.local> 1604040420 +0800
committer Rahul <rahul@Rahuls-MacBook-Pro.local> 1604278931 +0800

Implementing check and add functionality

create project

add pyenv-installer as default plugin

add pyenv-doctor

use https instead of git protocol

Remove unneeded escaping in here-doc

There is no need to escape double-quotes in here-doc strings. The current output contains a lot of '\"' that have to be converted to '"' manually.

Add pyenv-version-ext (pyenv/pyenv#96)

Point to the newer GitHub Raw URL

Old one wasn't working.

Follow HTTP redirects

Simplify

Display shell configurations based on user's shell

Update the list of plugins

Added missing quote to instructions after install

Add `eval "$(pyenv virtualenv-init -)"`

Add uninstallation procedure (fixes #10)

Use `git://github.com` to fix problem with ancient Git (refs #9)

prrof of concept

add vagrantfile and ignores

formatting

vagrant explanation

troves, docs, todos

add caveat about automating

remove docker key, whitespace

This works somwhow on TestPyPi

whipping fork into shape for merge.

add manifest

Add new option to install from PyPi.

add a version number (will likely need to be adapted)

ignore generated MANIFEST

use MANIFEST template

Installation instructions and copyright

meta data and long description from README.rst

fix copyright notice

fix short description

add info to copyright notice

add info to copyright notice

f*** the copyright notice ... dunno how and what to add :)

fix version number

Revert "f*** the copyright notice ... dunno how and what to add :)"

This reverts commit 9ce6161.

Use https to clone from github if `USE_HTTPS` is defined (fixes #12)

fix spelling mistake in readme.rst

Add warning for PyPi install

opened pyenv/pyenv-installer#25 to fix this

pip-rehash is a default feature of pyenv nowadays

Fixed PATH of pyenv-installer.

Added offline installer.

Fixed PATH of pyenv-offline-installer.

Changed CLI of pyenv-offline-installer.

Revert "Fixed PATH of pyenv-offline-installer."

This reverts commit ea44a1a.

Revert "Revert "Fixed PATH of pyenv-offline-installer.""

This reverts commit e0f14bf.

Revert "Changed CLI of pyenv-offline-installer."

This reverts commit a62269e.

Small fix on pyenv-offline-installer.

reversed the usage of https instead git://

added info for USE_GIT_URI

Update README.rst

made uninstallation instructions complete

Fix bug in doc

Use shallow clone for repo checkouts.

Syntax highlight in README.rst

Fix minor typo

point links to the correct repositories of pyenv

update copyright dates and have a single source of truth for the license

release date is to be determined

update and simplify the dummy package to finally "release" it.

don't recommend piping the internet through a shell

Update installer script URL to more pleasure

Fix repo URLs to point to `pyenv` organisation

exit with error if a git clone operation fails

PR from patch pyenv/pyenv-installer#40 (comment) - thanks @tuxlifan

prefer bashrc instead of bash_profile

prefer bashrc instead of bash_profile

fix rst - note to self always use twine check, even for little things.

Add the short url to install pyenv

Thanks @robnagler :)

follow redirects not necessary for pyen.run

fix release date / version

fix link syntax

Add suggestion to restart shell

Thanks @lymanZerga11!

fix: suggests removal of .pyenv folder on reinstallation

refactor: message changes

fix: .pyenv check moved right at the start

Explicitly set .pyenv PATH

This is breaking some customers, who just copy paste these lines into their `*rc` file

See pyenv/pyenv-virtualenv#233 (comment)

Adding hint for Travis

Integrating suggestion from pyenv/pyenv-installer#60

Update error message to use relative $PYENV_ROOT

When using a separate $PYENV_ROOT, the error message refers to the `.pyenv` directory living in $HOME.

Update headings in readme.

Formatting headings

Formatting headings

fix error about wrong command

+ Cloning into ''\''pyenv'\''...'
download-pyenv-package.sh: line 4: Cloning: command not found
@iTosun
Copy link

iTosun commented Apr 22, 2021

i had also some difficulties in windows WSL2 & zsh on ubuntu 20.04
I've removed the export command and that fixed it for me, now it looks like this at the end of my .zshrc

PATH="$HOME/.pyenv/bin:$PATH"     
if command -v pyenv 1>/dev/null 2>&1; then
   eval "$(pyenv init -)"                  
fi

@andrewsiah
Copy link

andrewsiah commented May 11, 2021

I've tried everything listed on this page, mine still doesn't work. This error message still pops up.

` Load pyenv automatically by appending
the following to ~/.zshrc:

eval "$(pyenv init -)" `

This is how my ~/.zshrc file looks like.
`export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"

!! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/andrew/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/andrew/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/andrew/opt/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/andrew/opt/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup

if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi `

@agoose77
Copy link

agoose77 commented May 21, 2021

@andrewsiah what distro are you using?

pyenv recently changed how it loads the configuration. It now requires the PYENV_HOME variable to be set, and eval "$(pyenv init --path)" to be run after you export PATH="$PYENV_ROOT/bin:$PATH". See the installation instructions for more.

@bytefluxio
Copy link

Found this issue after installing via the pyenv-installer. (zsh on wsl ubuntu running in conemu)
At first I added:

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

As mentioned in this thread. I got the following warning after restarting the shell:

WARNING: `pyenv init -` no longer sets PATH.
Run `pyenv init` to see the necessary changes to make to your configuration.

After running pyenv init, it pretty much told me to add eval "$pyenv init --path)" before the eval "$(pyenv init -)"` command. Which I did and now it works with the following:

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

However this means, that the pyenv-installer is currently broken. :(

@EM5813
Copy link

EM5813 commented Jul 3, 2021

I've tried so many variations and it's still not working. My current setup is

export PATH="~/.pyenv/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

erased .profile and .zshrenv

Still receiving zsh: command not found: pyenv

HELP!

@CarlosChiarelli
Copy link

export PYENV_ROOT="$HOME"/.pyenv
export PATH="$PYENV_ROOT"/bin:"$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
eval "$(pyenv virtualenv-init -)"

I'ts work! Thanks :D

@f4z3k4s
Copy link

f4z3k4s commented Sep 23, 2021

In case of M1 users:

Pyenv gets installed to /opt/homebrew/Cellar/...

So running pyenv which pyenv showed me that I have pyenv installed to /opt/homebrew/Cellar/pyenv/2.0.6/libexec/pyenv.

Therefore, I added this to my .zprofile:

eval "$(/opt/homebrew/Cellar/pyenv/2.0.6/libexec/pyenv init --path)" instead of eval "$(pyenv init --path)"

Works as expected.

@ScottGuthart
Copy link

In case of M1 users:

Pyenv gets installed to /opt/homebrew/Cellar/...

So running pyenv which pyenv showed me that I have pyenv installed to /opt/homebrew/Cellar/pyenv/2.0.6/libexec/pyenv.

Therefore, I added this to my .zprofile:

eval "$(/opt/homebrew/Cellar/pyenv/2.0.6/libexec/pyenv init --path)" instead of eval "$(pyenv init --path)"

Works as expected.

This works for me too! But I wonder if we'll have to change this whenever pyenv updates?

@native-api
Copy link
Member

Please see updated and hopefully clearer Pyenv shell setup instructions in https://github.com/pyenv/pyenv#readme
eval "$(pyenv virtualenv-init -)" should run in an rc file after eval "$(pyenv init -)" as before.

@ScottGuthart
Copy link

This is the issue I believe @f4z3k4s and I are experiencing. I think that I attempted to follow the updated homebrew shell setup instructions appropriately. But I still receive the command not found: pyenv error for line 3 in .zprofile as shown below which is resolved by substituting for line 4.

# .zshrc
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
# .zprofile
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH" 
# eval "$(pyenv init --path)" <-- causes .zprofile:3: command not found: pyenv
eval "$(/opt/homebrew/Cellar/pyenv/2.1.0/libexec/pyenv init --path)" # works

@native-api
Copy link
Member

native-api commented Oct 6, 2021

@ScottGuthart If you installed Pyenv with Homebrew, it should already be on PATH, in $(brew --prefix)/bin. If it's not, something is wrong with its installation.
It's also possible that you also have another version of Pyenv, installed from a Git checkout, that interferes with things. See pyenv/pyenv#1760 (comment).

@ScottGuthart
Copy link

@native-api gotcha, so maybe this is an issue just unique to me then. I don't think I've previously installed from git checkout but I did just migrate from an intel mac to an m1 mac, I'm guessing that's probably the cause of it somehow.

@no-response
Copy link

no-response bot commented Nov 5, 2021

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Nov 5, 2021
@earnestaddae
Copy link

Thanks!

@ounme
Copy link

ounme commented May 18, 2022

I've tried so many variations and it's still not working. My current setup is

HELP!

Absolutely nothing helped me either. In my case , I had to say goodbye to anaconda . For some reason, the system refused to load anything other than python inside anaconda

@sinnrrr
Copy link

sinnrrr commented Jul 12, 2022

For those, who have installed pyenv with Homebrew and have $(pyenv root)/bin in the profile file, do the following:

  1. echo $(pyenv root) in terminal and copy output (usually its $HOME/.pyenv)
  2. Replace $(pyenv root)/bin to our output ($HOME/.pyenv/bin)

@day0n
Copy link

day0n commented Jul 25, 2022

I had this issue, after following https://github.com/pyenv/pyenv-installer

I changed my ~/.zshrc from:

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

To

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

It works for me,I want to know why it works?

@native-api
Copy link
Member

It works for me,I want to know why it works?

~ is not expanded within quotes.

@josephsfuscos
Copy link

josephsfuscos commented Aug 9, 2022

I had this issue, after following https://github.com/pyenv/pyenv-installer

I changed my ~/.zshrc from:

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

To

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

This worked for me as well, the key for me was putting putting it in ~/.zshrc (not ~/.zshenv)

@bmasias1
Copy link

Currently im working on wsl2 with zsh, I change my .zshrc from:

export PATH=$HOME/bin:/usr/local/bin:$PATH`

To

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

@juliusgabrielalba
Copy link

I had this issue, after following https://github.com/pyenv/pyenv-installer

I changed my ~/.zshrc from:

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

To

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

worked like a charm ✨

@snakesgun
Copy link

This is my .profile and .zprofile settings which have solved the problem

  • .profile
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
  • .zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"

@yin-ori
Copy link

yin-ori commented Feb 13, 2023

for me this setup made shell find pyenv, BUT the export path for python packages is still opt/homebrew/lib/Python3.10 (which I don't even have installed anymore) for some reason. This also applies if I use the Mac standard Python (it will still download packages to the above path :S)
Does anyone know how I can amend it? I've been trying to change it for weeks now with no success (on Mac OS Ventura M1)
not sure if relevant ,but my pyenv which pyenv is /opt/homebrew/Cellar/pyenv/2.3.12/libexec/pyenv
and my pyenv virtual env is in this path: /Users/<myusername>/.pyenv/versions/3.11.1

.bash_profile
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

.bashrc is empty

.zprofile
# set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"

.zshrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

would be awesome if someone could help!

@MoorAE
Copy link

MoorAE commented Oct 19, 2023

this is my fix, i think for others like myself, it was a simple order of operation of the zsh; Order of reading startup files in zsh:
.zshenv → .zprofile → .zshrc → .zlogin

so now my .zshenv and .zprofile look like this:

eval "$(/usr/local/bin/brew shellenv)"
export PYENV_ROOT="$/usr/local/bin/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"

also i needed to create a .zprofile and .zshenv
(do the same instrustions for zprofile just swap zshenv)

@yin-ori check your .zshenv

@BorjaDiago
Copy link

I had same issue and just follow the configuration steps posted here https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv.

After make the necessary changes, the issue disappeared.

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

No branches or pull requests