Search code examples
pythonpython-3.xterminalzshrcpyenv

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


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 under 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; then\n 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.


Solution

  • 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; then\n 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.