Search code examples
pythonmacosterminalzshpyenv

While setting up pyenv, getting eval command not found


As title stated I'm setting up pyenv to run python 3.8.5 on my account on my friend Mac. The issues I believe is coming from this command in my ~/.zshrc file

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

So far I have check the $PATH command to ensure nothing is wrong with that and export command but haven't been able to fix the issue. Also tried using the above command in bash shell with the ~/.bash_profile at the end still doesn't work. I'm unable to run brew bash or brew zsh due to ownership issues.

I'm following this guide to set it up if that help.

updated:screenshotenter image description here enter image description here

Updated 2:enter image description here


Solution

  • After much discussion in the comments, we found several spacing problems: there were missing spaces, and one space that was a non-breaking space rather than a plain space:

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

    The non-breaking space is particularly tricky, since it's visually indistinguishable from a normal space. Piping the file through LC_ALL=C cat -v made it visible as "M-BM- ".

    Note: at least on the US keyboard on macOS, typing Option-space enters a non-breaking space. They usually get entered by mistake because the Option key was down for some reason when a supposed-to-be-normal space was typed.

    Editing the .zshrc file to add the missing spaces and remove the non-breaking space fixed it.

    BTW, I'll add a moral here: exact typing matters, and when you have a text source it's usually better to copy-and-paste rather than trying to retype something accurately.