Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign uppyenv init getting into an infinite loop when invoked from bashrc #264
Comments
This comment has been minimized.
This comment has been minimized.
It is pretty weird. I couldn't reproduce such strange behaviour at least on Debian/Ubuntu/OS X. The http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html The followings are my answers:
|
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
I confirmed that this doesn't reproduce with out-of-box Debian/Ubuntu. I created a Docker container for reproduction, but the % docker run -it yyuu/pyenv:issue264 bash -l
this is .bashrc
this is .profile
root@ddbcabcb80ef:/# I am wondering if I should fix this in This is the FROM ubuntu:14.04
MAINTAINER Yamashita, Yuu <peek824545201@gmail.com>
ENV PATH /root/.pyenv/shims:/root/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get --quiet --yes update
RUN apt-get --quiet --yes upgrade
RUN apt-get --quiet --yes install build-essential curl git libbz2-dev libreadline-dev libsqlite3-dev libssl-dev patch zlib1g-dev
RUN git clone --quiet https://github.com/yyuu/pyenv.git /root/.pyenv
RUN cd /root/.pyenv && git reset --hard 35aed21
RUN echo 'export BASH_ENV="/root/.bashrc"' >> /etc/profile
RUN echo 'echo "this is .profile"' >> /root/.profile
RUN echo 'echo "this is .bashrc"' >> /root/.bashrc
RUN echo 'eval "$(pyenv init -)"' >> /root/.bashrc
## Enable infinite loop
#RUN sed -i.orig -e '/^\[ -z "\$PS1" \]/s/^/#/' /root/.bashrc |
This comment has been minimized.
This comment has been minimized.
As I mentioned, I encountered this in CentOS rather than Debian. Apparently Debian/Ubuntu has the concept of only having .bashrc which has a hard-coded check for non-interactive shell in the beginning, whereas CentOS/RedHat has both a .bash_profile (which is run for login shells) and a .bashrc (which is meant to be run for non-interactive shells). In particular bash_profile sets BASH_ENV to point to .bashrc. The most easy way to reproduce the infinite loop is to change the line
to
in your Dockerfile, and then, for example, invoke pyenv. Yes, I think that this should be mentioned in the docs somewhere next to the installation instructions that require adding $(pyenv init -) to the startup script. |
This comment has been minimized.
This comment has been minimized.
山下 優 (やました ゆう) |
This comment has been minimized.
This comment has been minimized.
Adding warning in README has already been merged. |
This comment has been minimized.
This comment has been minimized.
Might be of value to others, but I conditionally initialized pyenv to avoid this problem. if [ -n "$(type -t pyenv)" ] && [ "$(type -t pyenv)" = function ]; then
# echo "pyenv is already initialized"
true
else
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
fi |
This comment has been minimized.
This comment has been minimized.
@StevenACoffman's solution didn't quite work for me on zsh, so I implemented a workaround using environment variables here:
|
The current installation instructions suggest to place the line
eval "$(pyenv init -)"
at the end of .bash_profile or .bashrc depending on the Linux flavor.
This suggestion may lead to the following scenario:
Obviously, the immediate fix for the problem is to put the initialization line into .bash_profile rather than .bashrc, however at the point in time, when the user encounters this error, this is far from obvious (in particular, this has been the reason for me to not start using pyenv the first time I tried it and had no time to debug the problem, and now it took quite some time to figure out what's happening).
It would be great to find some nice way to prevent this possibility for an infinite loop somehow. The options I'd see, in order of niceness: