Skip to content

Rewrite activate without using virtualenv/venv/conda's script #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 5, 2015

Conversation

yyuu
Copy link
Collaborator

@yyuu yyuu commented Nov 4, 2015

This should fix #69. I also aim this as a first step for #103

@blueyed how do you think about this? give me some feedback if you have time.

@blueyed
Copy link
Collaborator

blueyed commented Nov 5, 2015

Looks interesting and good.
I was not aware of these special cases before.

I do not like the setting of CONDA_DEFAULT_ENV though (https://github.com/yyuu/pyenv-virtualenv/pull/104/files#diff-73eaeed3203727516bca36b17f6b3842R238).

@yyuu
Copy link
Collaborator Author

yyuu commented Nov 5, 2015

We need to set CONDA_DEFAULT_ENV to mimic environments created by Anaconda/Miniconda. Although we don't have to set it always. I'll modify the activate script to set it up as few as possible.

yyuu added a commit that referenced this pull request Nov 5, 2015
Rewrite `activate` without using virtualenv/venv/conda's script
@yyuu yyuu merged commit 459d1aa into master Nov 5, 2015
@yyuu yyuu deleted the activate-ng branch November 5, 2015 09:39
@jimmywan
Copy link

I'm running into a problem where pyenv appears to be invoking some scripts in a loop that it can't get out of. If I run either of the following:

  • pyenv activate
  • pyenv virtualenvs

It gets into a loop running pyenv scripts over and over again:

ps -ef | grep -c pyenv
4982

Currently on the following:
pyenv 9ca7de5 (master)
pyenv-virtualenv de1deb1 (master)

My setup:
system is ubuntu VM:

Distributor ID: Ubuntu
Description: Ubuntu 14.04 LTS
Release: 14.04
Codename: trusty

shell is bash
.profile:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Let me know if there's any way I can help debug this.

@jimmywan
Copy link

Also tried activating my env via the following which failed in the same manner:
pyenv shell miniconda-3.16.0/envs/myenv

@jimmywan
Copy link

If this helps, the ps output looks like this(repeated over and over):
If this helps, the ps output:

jimmy 32667 32654 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-which python
jimmy 32668 32667 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-virtualenv-prefix
jimmy 32673 32668 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-virtualenv-prefix
jimmy 32675 32673 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-exec python -c import sys;print(sys.real_prefix)
jimmy 32685 32675 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-which python
jimmy 32706 32685 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-which python
jimmy 32707 32706 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-virtualenv-prefix
jimmy 32712 32707 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-virtualenv-prefix
jimmy 32713 32712 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-exec python -c import sys;print(sys.real_prefix)
jimmy 32715 32713 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-which python
jimmy 32728 32715 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-which python
jimmy 32729 32728 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-virtualenv-prefix
jimmy 32732 32729 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-virtualenv-prefix
jimmy 32733 32732 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-exec python -c import sys;print(sys.real_prefix)
jimmy 32735 32733 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-which python
jimmy 32748 32735 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-which python
jimmy 32749 32748 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-virtualenv-prefix
jimmy 32752 32749 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-virtualenv-prefix
jimmy 32753 32752 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-exec python -c import sys;print(sys.real_prefix)
jimmy 32755 32753 0 17:17 pts/6 00:00:00 bash /home/jimmy/.pyenv/libexec/pyenv-which python

@yyuu
Copy link
Collaborator Author

yyuu commented Nov 13, 2015

@jimmywan That's bad 😞 If you can use Docket, could you prepare some Dockerfile to reproduce the error in container? It'd help me a lot to dig into the issue....

@jimmywan
Copy link

I assume you meant Docker, and not Docket. I will give it a try.

@jimmywan
Copy link

(Updated with a better script and more detail)
@yyuu here's a Dockerfile that reproduces the issue:

FROM buildpack-deps:jessie-curl

################################################################################
# CONFIGURE PYTHON START
################################################################################
ENV HOME=/root

# Install git/bzip2 (required by miniconda)
RUN DEBIAN_FRONTEND=noninteractive \
    apt-get update \
    && apt-get install -q -y bzip2 git \
    && echo "===> clean up..." \
    && apt-get clean \
    && apt-get autoremove \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install pyenv
RUN DEBIAN_FRONTEND=noninteractive \
    git clone https://github.com/yyuu/pyenv.git ${HOME}/.pyenv

# Instal pyenv-virtualenv
RUN DEBIAN_FRONTEND=noninteractive \
    git clone https://github.com/yyuu/pyenv-virtualenv.git ${HOME}/.pyenv/plugins/pyenv-virtualenv

ENV PYENV_ROOT="${HOME}/.pyenv"
ENV PATH="${PYENV_ROOT}/bin:$PATH"

RUN DEBIAN_FRONTEND=noninteractive \
    pyenv install miniconda-3.16.0

# Generate conda-requirements file
RUN DEBIAN_FRONTEND=noninteractive \
    && echo '# Install conda updates' >> ${HOME}/conda-requirements.txt \
    && echo '# This file may be used to create an environment using:' >> ${HOME}/conda-requirements.txt \
    && echo '# $ conda create --name <env> --file <this file>' >> ${HOME}/conda-requirements.txt \
    && echo '# platform: linux-64' >> ${HOME}/conda-requirements.txt \
    && echo 'cairo=1.12.18=2' >> ${HOME}/conda-requirements.txt \
    && echo 'fontconfig=2.11.1=2' >> ${HOME}/conda-requirements.txt \
    && echo 'freetype=2.5.2=0' >> ${HOME}/conda-requirements.txt \
    && echo 'libgfortran=1.0=0' >> ${HOME}/conda-requirements.txt \
    && echo 'libpng=1.5.13=1' >> ${HOME}/conda-requirements.txt \
    && echo 'libxml2=2.9.0=0' >> ${HOME}/conda-requirements.txt \
    && echo 'matplotlib=1.4.3=np19py27_1' >> ${HOME}/conda-requirements.txt \
    && echo 'numpy=1.9.2=py27_1' >> ${HOME}/conda-requirements.txt \
    && echo 'openblas=0.2.14=1' >> ${HOME}/conda-requirements.txt \
    && echo 'pandas=0.16.2=np19py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'patsy=0.3.0=np19py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'pixman=0.26.2=0' >> ${HOME}/conda-requirements.txt \
    && echo 'py2cairo=1.10.0=py27_2' >> ${HOME}/conda-requirements.txt \
    && echo 'pyparsing=2.0.3=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'pyqt=4.11.3=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'python-dateutil=2.4.2=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'pytz=2015.4=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'qt=4.8.6=0' >> ${HOME}/conda-requirements.txt \
    && echo 'readline=6.2=2' >> ${HOME}/conda-requirements.txt \
    && echo 'sip=4.16.5=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'six=1.9.0=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'sqlite=3.8.4.1=1' >> ${HOME}/conda-requirements.txt \
    && echo 'statsmodels=0.6.1=np19py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'tk=8.5.18=0' >> ${HOME}/conda-requirements.txt \
    && echo 'wheel=0.24.0=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'zlib=1.2.8=0' >> ${HOME}/conda-requirements.txt

# Create conda environment
RUN DEBIAN_FRONTEND=noninteractive \
    eval "$(pyenv init -)" \
    && eval "$(pyenv virtualenv-init -)" \
    && pyenv versions \
    && pyenv global miniconda-3.16.0 \
    && conda create -y --file ${HOME}/conda-requirements.txt --name testenv

CMD \
    echo '#!/bin/bash' >> ${HOME}/test.sh \
    && echo 'eval "$(pyenv init -)"' >> ${HOME}/test.sh \
    && echo 'eval "$(pyenv virtualenv-init -)"' >> ${HOME}/test.sh \
    && echo 'pyenv versions' >> ${HOME}/test.sh \
    && echo 'pyenv deactivate' >> ${HOME}/test.sh \
    && echo 'echo activating miniconda-3.16.0/envs/testenv' >> ${HOME}/test.sh \
    && echo 'pyenv activate miniconda-3.16.0/envs/testenv &' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && chmod 700 ${HOME}/test.sh \
    && echo "Testing v20151006" \
    && cd ${PYENV_ROOT} \
    && git checkout -q v20151006 \
    && cd plugins/pyenv-virtualenv \
    && git checkout -q v20151006 \
    && ${HOME}/test.sh \
    && echo "Testing master" \
    && cd ${PYENV_ROOT} \
    && git checkout -q master \
    && cd plugins/pyenv-virtualenv \
    && git checkout -q master \
    && ${HOME}/test.sh

Sample output:

Testing v20151006
* miniconda-3.16.0 (set by /root/.pyenv/version)
pyenv-virtualenv: no virtualenv has been activated.
activating miniconda-3.16.0/envs/testenv
found 7 bash processes
pyenv-virtualenv: Only bash and zsh are supported by Anaconda/Miniconda
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 3 bash processes
Testing master
* miniconda-3.16.0 (set by /root/.pyenv/version)
  miniconda-3.16.0/envs/testenv
pyenv-virtualenv: no virtualenv has been activated.
activating miniconda-3.16.0/envs/testenv
found 7 bash processes
found 228 bash processes
found 453 bash processes
found 681 bash processes
found 911 bash processes
found 1142 bash processes
found 1391 bash processes
found 1633 bash processes
found 1870 bash processes
found 2106 bash processes

@yyuu
Copy link
Collaborator Author

yyuu commented Nov 25, 2015

@jimmywan Hmm. Thanks for preparing it. I'll give it a try later.

@yyuu
Copy link
Collaborator Author

yyuu commented Nov 26, 2015

@jimmywan I confirmed the reproduction. The cause of the issue would be absence of python executable in conda's env of testenv. Installing python package on creating new env would mitigate the issue for now. I'll try to prepare some workaround for it later.

@yyuu
Copy link
Collaborator Author

yyuu commented Nov 26, 2015

The root cause of the problem on absence of python executable would be introduced in 21239c9. As a side effect of stop using activate script, since it doesn't manage PATH anymore, this has became actual. I should have not used pyenv-virtualenv-prefix in the hooks for pyenv-which....

yyuu added a commit that referenced this pull request Nov 26, 2015
…table (#104)

conda's environment might not have `python` executable. If the prefix
doesn't contain `python` in it, `pyenv-which` might be ran into infinite
loop if some of `which` hooks invoke `pyenv-virtualenv-prefix`.
yyuu added a commit that referenced this pull request Nov 26, 2015
@yyuu
Copy link
Collaborator Author

yyuu commented Nov 26, 2015

@jimmywan I pushed some workaround for the problem as 35732c8. Please give it a try.

@jimmywan
Copy link

@yyuu , thanks for investigating. As a temporary workaround, I could probably add python to my declared dependencies when creating the env. I had already discovered that while using v20151006 I needed to add pip to my dependencies since it would fallback on the non-env pip and install dependencies for miniconda and not test_env, so it wouldn't be that big a deal to add python to that list.

@jimmywan
Copy link

Confirmed that my docker container now runs without bash processes spiraling out of control, but I'm not entirely sure that everything is working fine.

I tried to do some rudimentary testing to reproduce the original problem where a virtualenv was missing python and I managed to hose my virtualenv.

I did the following:
activate virtualenv (pyenv activate )
removed python (conda uninstall python)

After I did that, my virtualenv could not be reactivated.
It shows up under "pyenv versions", but does not show up under "pyenv virtualenvs"

Tried to make a slight modification to my test script from before to make this reproducible.

FROM buildpack-deps:jessie-curl

################################################################################
# CONFIGURE PYTHON START
################################################################################
ENV HOME=/root

# Install git/bzip2 (required by miniconda)
RUN DEBIAN_FRONTEND=noninteractive \
    apt-get update \
    && apt-get install -q -y bzip2 git \
    && echo "===> clean up..." \
    && apt-get clean \
    && apt-get autoremove \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install pyenv
RUN DEBIAN_FRONTEND=noninteractive \
    git clone https://github.com/yyuu/pyenv.git ${HOME}/.pyenv

# Instal pyenv-virtualenv
RUN DEBIAN_FRONTEND=noninteractive \
    git clone https://github.com/yyuu/pyenv-virtualenv.git ${HOME}/.pyenv/plugins/pyenv-virtualenv

ENV PYENV_ROOT="${HOME}/.pyenv"
ENV PATH="${PYENV_ROOT}/bin:$PATH"

RUN DEBIAN_FRONTEND=noninteractive \
    pyenv install miniconda-3.16.0

# Generate conda-requirements file
RUN DEBIAN_FRONTEND=noninteractive \
    && echo '# Install conda updates' >> ${HOME}/conda-requirements.txt \
    && echo '# This file may be used to create an environment using:' >> ${HOME}/conda-requirements.txt \
    && echo '# $ conda create --name <env> --file <this file>' >> ${HOME}/conda-requirements.txt \
    && echo '# platform: linux-64' >> ${HOME}/conda-requirements.txt \
    && echo 'cairo=1.12.18=2' >> ${HOME}/conda-requirements.txt \
    && echo 'fontconfig=2.11.1=2' >> ${HOME}/conda-requirements.txt \
    && echo 'freetype=2.5.2=0' >> ${HOME}/conda-requirements.txt \
    && echo 'libgfortran=1.0=0' >> ${HOME}/conda-requirements.txt \
    && echo 'libpng=1.5.13=1' >> ${HOME}/conda-requirements.txt \
    && echo 'libxml2=2.9.0=0' >> ${HOME}/conda-requirements.txt \
    && echo 'matplotlib=1.4.3=np19py27_1' >> ${HOME}/conda-requirements.txt \
    && echo 'numpy=1.9.2=py27_1' >> ${HOME}/conda-requirements.txt \
    && echo 'openblas=0.2.14=1' >> ${HOME}/conda-requirements.txt \
    && echo 'pandas=0.16.2=np19py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'patsy=0.3.0=np19py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'pixman=0.26.2=0' >> ${HOME}/conda-requirements.txt \
    && echo 'py2cairo=1.10.0=py27_2' >> ${HOME}/conda-requirements.txt \
    && echo 'pyparsing=2.0.3=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'pyqt=4.11.3=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'python-dateutil=2.4.2=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'pytz=2015.4=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'qt=4.8.6=0' >> ${HOME}/conda-requirements.txt \
    && echo 'readline=6.2=2' >> ${HOME}/conda-requirements.txt \
    && echo 'sip=4.16.5=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'six=1.9.0=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'sqlite=3.8.4.1=1' >> ${HOME}/conda-requirements.txt \
    && echo 'statsmodels=0.6.1=np19py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'tk=8.5.18=0' >> ${HOME}/conda-requirements.txt \
    && echo 'wheel=0.24.0=py27_0' >> ${HOME}/conda-requirements.txt \
    && echo 'zlib=1.2.8=0' >> ${HOME}/conda-requirements.txt

# Create conda environment
RUN DEBIAN_FRONTEND=noninteractive \
    eval "$(pyenv init -)" \
    && eval "$(pyenv virtualenv-init -)" \
    && pyenv versions \
    && pyenv global miniconda-3.16.0 \
    && conda create -y --file ${HOME}/conda-requirements.txt --name testenv

CMD \
    echo '#!/bin/bash' >> ${HOME}/test.sh \
    && echo 'eval "$(pyenv init -)"' >> ${HOME}/test.sh \
    && echo 'eval "$(pyenv virtualenv-init -)"' >> ${HOME}/test.sh \
    && echo 'echo pyenv version' >> ${HOME}/test.sh \
    && echo 'pyenv version' >> ${HOME}/test.sh \
    && echo 'echo pyenv versions' >> ${HOME}/test.sh \
    && echo 'pyenv versions' >> ${HOME}/test.sh \
    && echo 'echo pyenv virtualenvs' >> ${HOME}/test.sh \
    && echo 'pyenv virtualenvs' >> ${HOME}/test.sh \
    && echo 'echo pyenv deactivate' >> ${HOME}/test.sh \
    && echo 'pyenv deactivate' >> ${HOME}/test.sh \
    && echo 'echo pyenv version' >> ${HOME}/test.sh \
    && echo 'pyenv version' >> ${HOME}/test.sh \
    && echo 'echo activating miniconda-3.16.0/envs/testenv' >> ${HOME}/test.sh \
    && echo 'pyenv activate miniconda-3.16.0/envs/testenv &' >> ${HOME}/test.sh \
    && echo 'echo pyenv version' >> ${HOME}/test.sh \
    && echo 'pyenv version' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && echo 'echo found `ps -ef | grep -c bash` bash processes' >> ${HOME}/test.sh \
    && echo 'sleep 1' >> ${HOME}/test.sh \
    && chmod 700 ${HOME}/test.sh \
    && echo "Testing v20151006" \
    && cd ${PYENV_ROOT} \
    && git checkout -q v20151006 \
    && cd plugins/pyenv-virtualenv \
    && git checkout -q v20151006 \
    && ${HOME}/test.sh \
    && echo "Testing master" \
    && cd ${PYENV_ROOT} \
    && git checkout -q master \
    && git pull \
    && cd plugins/pyenv-virtualenv \
    && git checkout -q master \
    && git pull \
    && ${HOME}/test.sh \
    && echo '#!/bin/bash' >> ${HOME}/test2.sh \
    && echo 'eval "$(pyenv init -)"' >> ${HOME}/test2.sh \
    && echo 'eval "$(pyenv virtualenv-init -)"' >> ${HOME}/test2.sh \
    && echo 'echo pyenv version' >> ${HOME}/test2.sh \
    && echo 'pyenv version' >> ${HOME}/test2.sh \
    && echo 'echo pyenv versions' >> ${HOME}/test2.sh \
    && echo 'pyenv versions' >> ${HOME}/test2.sh \
    && echo 'echo pyenv virtualenvs' >> ${HOME}/test2.sh \
    && echo 'pyenv virtualenvs' >> ${HOME}/test2.sh \
    && echo 'echo conda env list' >> ${HOME}/test2.sh \
    && echo 'conda env list' >> ${HOME}/test2.sh \
    && echo 'echo pyenv deactivate' >> ${HOME}/test2.sh \
    && echo 'pyenv deactivate' >> ${HOME}/test2.sh \
    && echo 'echo activating miniconda-3.16.0/envs/testenv' >> ${HOME}/test2.sh \
    && echo 'pyenv activate miniconda-3.16.0/envs/testenv' >> ${HOME}/test2.sh \
    && echo 'echo pyenv version' >> ${HOME}/test2.sh \
    && echo 'pyenv version' >> ${HOME}/test2.sh \
    && echo 'echo pyenv versions' >> ${HOME}/test2.sh \
    && echo 'pyenv versions' >> ${HOME}/test2.sh \
    && echo 'echo pyenv virtualenvs' >> ${HOME}/test2.sh \
    && echo 'pyenv virtualenvs' >> ${HOME}/test2.sh \
    && echo 'echo conda env list' >> ${HOME}/test2.sh \
    && echo 'conda env list' >> ${HOME}/test2.sh \
    && echo 'echo "pyenv which conda"' >> ${HOME}/test2.sh \
    && echo 'pyenv which conda' >> ${HOME}/test2.sh \
    && echo 'echo "removing python"' >> ${HOME}/test2.sh \
    && echo 'conda uninstall python' >> ${HOME}/test2.sh \
    && echo 'echo pyenv version' >> ${HOME}/test2.sh \
    && echo 'pyenv version' >> ${HOME}/test2.sh \
    && echo 'echo pyenv versions' >> ${HOME}/test2.sh \
    && echo 'pyenv versions' >> ${HOME}/test2.sh \
    && echo 'echo pyenv virtualenvs' >> ${HOME}/test2.sh \
    && echo 'pyenv virtualenvs' >> ${HOME}/test2.sh \
    && chmod 700 ${HOME}/test2.sh \
    && ${HOME}/test2.sh

Here is my output (anything starting with a '#' is hand added commentary except for the output of conda env list):

$ docker run -it pyenv_test
Testing v20151006
pyenv version
miniconda-3.16.0 (set by /root/.pyenv/version)
pyenv versions
* miniconda-3.16.0 (set by /root/.pyenv/version)
pyenv virtualenvs
* miniconda-3.16.0 (created from /root/.pyenv/versions/miniconda-3.16.0)
  miniconda-3.16.0/envs/testenv (created from /root/.pyenv/versions/miniconda-3.16.0)
pyenv deactivate
pyenv-virtualenv: no virtualenv has been activated.
pyenv version
miniconda-3.16.0 (set by /root/.pyenv/version)
activating miniconda-3.16.0/envs/testenv
pyenv version
pyenv-virtualenv: Only bash and zsh are supported by Anaconda/Miniconda
miniconda-3.16.0 (set by /root/.pyenv/version)
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 3 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes

Testing master
Already up-to-date.
Already up-to-date.
pyenv version
miniconda-3.16.0 (set by /root/.pyenv/version)
pyenv versions
* miniconda-3.16.0 (set by /root/.pyenv/version)
  miniconda-3.16.0/envs/testenv
pyenv virtualenvs
* miniconda-3.16.0 (created from /root/.pyenv/versions/miniconda-3.16.0)
pyenv deactivate
pyenv-virtualenv: no virtualenv has been activated.
pyenv version
miniconda-3.16.0 (set by /root/.pyenv/version)
activating miniconda-3.16.0/envs/testenv
pyenv version
miniconda-3.16.0 (set by /root/.pyenv/version)
found 13 bash processes
pyenv-virtualenv: version `miniconda-3.16.0/envs/testenv' is not a virtualenv # This was the message from activate launched in a background shell. This should have worked?
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes
found 4 bash processes

pyenv version
miniconda-3.16.0 (set by /root/.pyenv/version)
pyenv versions # conda env now shows up under versions
* miniconda-3.16.0 (set by /root/.pyenv/version)
  miniconda-3.16.0/envs/testenv
pyenv virtualenvs # Interesting that my conda env does not show up undervirtualenvs
* miniconda-3.16.0 (created from /root/.pyenv/versions/miniconda-3.16.0)
conda env list
# conda environments:
#
testenv                  /root/.pyenv/versions/miniconda-3.16.0/envs/testenv
root                  *  /root/.pyenv/versions/miniconda-3.16.0

pyenv deactivate
pyenv-virtualenv: no virtualenv has been activated.
activating miniconda-3.16.0/envs/testenv # Seems like this should have worked
pyenv-virtualenv: version `miniconda-3.16.0/envs/testenv' is not a virtualenv
pyenv version
miniconda-3.16.0 (set by /root/.pyenv/version)
pyenv versions
* miniconda-3.16.0 (set by /root/.pyenv/version)
  miniconda-3.16.0/envs/testenv
pyenv virtualenvs
* miniconda-3.16.0 (created from /root/.pyenv/versions/miniconda-3.16.0)
conda env list
# conda environments:
#
testenv                  /root/.pyenv/versions/miniconda-3.16.0/envs/testenv
root                  *  /root/.pyenv/versions/miniconda-3.16.0

pyenv which conda
/root/.pyenv/versions/miniconda-3.16.0/bin/conda
removing python # This fails, but I didn't expect to be in the root environment
Fetching package metadata: ....
Error: cannot remove python, pycosat, pyyaml, conda, openssl, requests from root environment
pyenv version
miniconda-3.16.0 (set by /root/.pyenv/version)
pyenv versions
* miniconda-3.16.0 (set by /root/.pyenv/version)
  miniconda-3.16.0/envs/testenv
pyenv virtualenvs
* miniconda-3.16.0 (created from /root/.pyenv/versions/miniconda-3.16.0)

@yyuu
Copy link
Collaborator Author

yyuu commented Dec 2, 2015

@jimmywan pyenv activate miniconda-3.16.0/envs/testenv is failing due to absence of python executable in testenv. If python isn't present, pyenv virtulaenv-prefix detect the version as not a virtualenv. Please add python package explicitly when conda create.

https://github.com/yyuu/pyenv-virtualenv/blob/cf7dea411dca932e8a0dc6930eb608863da91502/bin/pyenv-virtualenv-prefix#L40

@jimmywan
Copy link

jimmywan commented Dec 3, 2015

My apologies, I had misunderstood that the suggested workaround was now required. Adding in python made everything work. I'll adjust my package requirements to include it (arguably should have already been in there).

The virtualenv where I had removed python is now "unreachable" since I can't activate it, but I suppose uninstalling python isn't a very reasonable use case. Perhaps a failed python upgrade could cause the same symptoms, but that seems to be a fairly obscure corner case.

@yyuu
Copy link
Collaborator Author

yyuu commented Dec 3, 2015

@jimmywan Good to know. Feel free to open an issue or send me some patch if you find sone issue about interoperability with conda!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not use virtualenv's (de)activate scripts?
3 participants