While setting up pyenv, getting eval command not found
Asked Answered
T

1

1

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

Territoriality answered 25/7, 2020 at 21:55 Comment(15)
It looks like the command you added to your .zshrc (and .bash_profile) is missing some spaces, specifically between eval and the double-quote, and also between init and the dash. There may be other problems, but those are the ones I see. Since this has been added incorrectly to those files, you'll need to edit them to fix the problem (just running the command again won't do it, it'll just add a correct version in addition to the incorrect version).Cornstalk
@GordonDavisson I have fixed the spacing but am still getting the errorTerritoriality
@JScottAnderson You are still getting exactly the same error after fixing typos in your command (echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc)? Can you check that your ~/.zshrc doesn't have that error from previous run of that erroneous command? And also be sure to restart your shell (e.g. exec "$SHELL") after all that!Andesine
@Andesine I have check and restarted the shell. Error still remainTerritoriality
@JScottAnderson that's really strange, can you maybe show us your ~/.zshrc or at least grep few lines around eval command from the same file, just to be sure? Output of grep -C 3 eval ~/.zshrc should be enough I suppose...Andesine
@Andesine Added the screenshot with grep commandTerritoriality
I have to admit that I never saw command not found: eval error :| Just curious, what happens when you run eval "$(pyenv init -)" in your shell?Andesine
Those error messages look slightly weird -- there's an extra space between "command not found:" and "eval". This suggests there may be something like a non-breaking space instead of a regular space, which looks ok but will not work properly. Try running grep eval ~/.zshrc | LC_ALL=C cat -vCornstalk
@Andesine running it in the shell work fine no errorTerritoriality
@GordonDavisson I got this as the result after running that command [M-BM- eval " $(pyenv init - ) "]Territoriality
That's what I thought. That "M-BM- " thing before "eval" is how it's displaying a non-breaking space character. You need to use an editor to delete the character right before "eval".Cornstalk
@GordonDavisson so i have to use one other than vi?Territoriality
vi should work. Just place the cursor on the character before "eval", and press x. BTW, it shouldn't matter, but I'd also recommend deleting the extra spaces inside the double-quotes, i.e. " $(pyenv init-) " -> "$(pyenv init-)".Cornstalk
If you want a GUI editor for scripting, I'd recommend BBEdit. It has an option to show normally-invisible weird characters (View menu -> Text Display -> Show Invisibles). It'll show a light grey circle in non-breaking spaces, rather than having them look just like normal spaces. Even if you don't buy it, its free/limited mode is pretty good.Cornstalk
Let us continue this discussion in chat.Territoriality
C
2

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.

Cornstalk answered 26/7, 2020 at 2:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.