pyenv appends .zshrc file with spam at every `source`

Question:

I am trying to setup python 3.7.3 to be my default python.
I am following this guide https://opensource.com/article/19/5/python-3-default-mac undre the chapter What we should do at the bottom of the page.

It works fine besides it appends my .zshrc file with:

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

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

Every time I open the terminal or run source ~/.zshrc it will put another of the following at the bottom of my config:

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

I get python v2 if I remove if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
, change the >> ~/.zshrc to >> ~/.zshrc_temp or remove it completely
Any ideas?

I am using MacOS Mojave 10.14 and iTerm2 if that matters.

Asked By: Kevin Neville

||

Answers:

I think I solved this! I complete removed

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

and every

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

except one.

Pyenv still seems to work as intended after this and no new lines are being appended to my .zshrc

Answered By: Adam Whitehurst

This is not a problem related to pyenv, you just don’t understand what .zshrc is.

.zshrc is the init/config file for ZSH. Whenever you open a new interactive ZSH shell, ZSH run the content within.

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

The content above appends the pyenv init script into .zshrc over and over.

I don’t know where you copied the echo -e ... command. It’s supposed run in the shell, not put into the .zshrc.

Answered By: Simba

I came to this post because of the same issue, then I found out why it happened:
I followed the instruction to install pyenv incorrectly, by pasting the following command to .zshrc, which was supposed to be running in the terminal directly.

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc

In order words, to solve the issue, you can simple remove these lines from the .zshrc and it will never bother you again.

Answered By: louielyl