Skip to content
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

Can not access Anaconda/Miniconda environment as virtualenv #178

Closed
oscargicast opened this issue Jun 19, 2016 · 30 comments · Fixed by #290
Closed

Can not access Anaconda/Miniconda environment as virtualenv #178

oscargicast opened this issue Jun 19, 2016 · 30 comments · Fixed by #290

Comments

@oscargicast
Copy link

oscargicast commented Jun 19, 2016

I'm showing you the steps I use to create a virtualenv based on miniconda. Finally you will see that the virtualenv was created but I can't access to it.

1.0. Check my initial pyenv versions:

$ pyenv versions
* system (set by /home/oscar/.python-version)
2.7.9
3.5.1

1.1 Install miniconda:

$ pyenv install miniconda3-4.0.5

$ pyenv versions
* system (set by /home/oscar/.python-version)
  2.7.9
  3.5.1
  miniconda3-4.0.5

1.2. Create the venvtest virtualenv based on miniconda:

$ pyenv virtualenv miniconda3-4.0.5 venvtest

$ pyenv versions
* system (set by /home/oscar/.python-version)
  2.7.9
  3.5.1
  miniconda3-4.0.5
  miniconda3-4.0.5/envs/venvtest
  venvtest

When I want to check if the virtualenv was created, It doesn't show it. So I can't no access to it 😢

$ pyenv virtualenvs
  miniconda3-4.0.5 (created from /home/oscar/.pyenv/versions/miniconda3-4.0.5)

$ pyenv activate ... (autocompleting)
--help            miniconda3-4.0.5  --unset 

Please, I hope you can help me.

@quietcoolwu
Copy link

quietcoolwu commented Jun 25, 2016

@yyuu The same problem happened to me, but it's still OK when I installed Anaconda or Miniconda with older conda version(e.g. 4.0.5), and using pyenv virtualenv to create a virtualenv. That is to say all works normally with older conda version after pyenv update.
I saw the conda update-log showed that it fixed shell recursion with activate problem in 4.1.3, but when I update to this version the problem remains.

@yyuu
Copy link
Collaborator

yyuu commented Jul 5, 2016

I couldn't reproduce the issue. It's all working for me even with conda 4.1.4.

% conda --version
conda 4.1.4
% pyenv virtualenv anaconda3-4.1.0 foo
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment /home/yyuu/.pyenv/versions/anaconda3-4.1.0/envs/foo:

The following NEW packages will be INSTALLED:

    openssl:    1.0.2h-1     
    pip:        8.1.2-py35_0 
    python:     3.5.1-5      
    readline:   6.2-2        
    setuptools: 23.0.0-py35_0
    sqlite:     3.13.0-0     
    tk:         8.5.18-0     
    wheel:      0.29.0-py35_0
    xz:         5.2.2-0      
    zlib:       1.2.8-3      

Linking packages ...
[      COMPLETE      ]|###########################################################################################################################################################| 100%
#
# To activate this environment, use:
# $ source activate foo
#
# To deactivate this environment, use:
# $ source deactivate
#
Installing pip from https://bootstrap.pypa.io/get-pip.py...
Requirement already up-to-date: pip in /home/yyuu/.pyenv/versions/anaconda3-4.1.0/envs/foo/lib/python3.5/site-packages
% pyenv virtualenvs
* anaconda3-4.1.0 (created from /home/yyuu/.pyenv/versions/anaconda3-4.1.0)
  anaconda3-4.1.0/envs/foo (created from /home/yyuu/.pyenv/versions/anaconda3-4.1.0/envs/foo)
  foo (created from /home/yyuu/.pyenv/versions/foo)
  miniconda3-4.0.5 (created from /home/yyuu/.pyenv/versions/miniconda3-4.0.5)
% pyenv activate foo
% pyenv virtualenvs
  anaconda3-4.1.0 (created from /home/yyuu/.pyenv/versions/anaconda3-4.1.0)
  anaconda3-4.1.0/envs/foo (created from /home/yyuu/.pyenv/versions/anaconda3-4.1.0/envs/foo)
* foo (created from /home/yyuu/.pyenv/versions/foo)
  miniconda3-4.0.5 (created from /home/yyuu/.pyenv/versions/miniconda3-4.0.5)

@yyuu yyuu closed this as completed Jul 5, 2016
@TheBurnDoc
Copy link

TheBurnDoc commented Jul 13, 2016

For me, on conda 4.1.2 I had to run source ~/.pyenv/versions/<env_dir>/bin/activate <env_name> at least once to make it work

@motivic
Copy link

motivic commented Dec 30, 2017

This issue is resurfacing with conda 4.4.1

% pyenv virtualenv miniconda3-latest test
Solving environment: done

## Package Plan ##

  environment location: /home/johnson/.pyenv/versions/miniconda3-latest/envs/test

  added / updated specs: 
    - python


The following NEW packages will be INSTALLED:

    ca-certificates: 2017.08.26-h1d4fec5_0   
    certifi:         2017.11.5-py36hf29ccca_0
    libedit:         3.1-heed3624_0          
    libffi:          3.2.1-hd88cf55_4        
    libgcc-ng:       7.2.0-h7cc24e2_2        
    libstdcxx-ng:    7.2.0-h7a57d05_2        
    ncurses:         6.0-h9df7e31_2          
    openssl:         1.0.2n-hb7f436b_0       
    pip:             9.0.1-py36h6c6f9ce_4    
    python:          3.6.4-hc3d631a_0        
    readline:        7.0-ha6073c6_4          
    setuptools:      36.5.0-py36he42e2e1_0   
    sqlite:          3.20.1-hb898158_2       
    tk:              8.6.7-hc745277_3        
    wheel:           0.30.0-py36hfd4bba0_1   
    xz:              5.2.3-h55aa19d_2        
    zlib:            1.2.11-ha838bed_2       

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate test
#
# To deactivate an active environment, use:
# > source deactivate
#

Requirement already satisfied: setuptools in /home/johnson/.pyenv/versions/miniconda3-latest/envs/test/lib/python3.6/site-packages
Requirement already satisfied: pip in /home/johnson/.pyenv/versions/miniconda3-latest/envs/test/lib/python3.6/site-packages

% pyenv activate test                                                   
pyenv-virtualenv: version `test' is not a virtualenv

Also, conda and activate are both missing from ~/.pyenv/versions/test/bin:

  % ls ~/.pyenv/versions/test/bin                                          !930
2to3              lzgrep            python3.6m         unxz
2to3-3.6          lzless            python3.6m-config  wheel
captoinfo         lzma              python3-config     wish
clear             lzmadec           pyvenv             wish8.6
c_rehash          lzmainfo          pyvenv-3.6         xz
easy_install      lzmore            reset              xzcat
easy_install-3.6  ncursesw6-config  sqlite3            xzcmp
idle3             openssl           sqlite3_analyzer   xzdec
idle3.6           pip               tabs               xzdiff
infocmp           pydoc             tclsh              xzegrep
infotocap         pydoc3            tclsh8.6           xzfgrep
lzcat             pydoc3.6          tic                xzgrep
lzcmp             python            toe                xzless
lzdiff            python3           tput               xzmore
lzegrep           python3.6         tset
lzfgrep           python3.6-config  unlzma

Update: Reverting back to conda 4.3.23 resolved the issue. Seems to be caused by an update in conda 4.4 that changed how conda manages environments.

@willprice
Copy link

I too am having the same issue describe by @motivic. Reverting back to 4.3.27 fixes the issue for me, was running miniconda3-latest installed this morning (4.4.6)

@AdityaGudimella
Copy link

@TurboTim 's suggestion still works with conda 4.4.* though.

@omdv
Copy link

omdv commented Jan 22, 2018

Confirming that I had the described issue with conda-4.4.7, which disappeared after downgrading conda to 4.3.30

@gzagatti
Copy link

I managed to make it work after downgrading to miniconda3-4.3.27 and downgrading conda within miniconda to the same version. Finally, I made sure to create a new conda environment using pyenv.

@vrastogi
Copy link

Facing this same issue here with conda 4.4.10. For me there does not appear to be an activate in bin of the env created.

@willprice
Copy link

conda 4.x switched to using conda activate env-name

@vrastogi
Copy link

Thanks, the comment by @willprice helps to at least enable the environments with conda. Activate the environment does not work with pyenv activate however.

@frankhinek
Copy link

I'm having the exact same issue.

@yyuu Are there plans to fix this for versions of conda > 4.4.x?

@Moulick
Copy link

Moulick commented Feb 26, 2018

Yep, Still a big issue

@Moulick
Copy link

Moulick commented Feb 26, 2018

Although the method by @willprice didn't work, the one above by @TurboTim works

For me, on conda 4.1.2 I had to run source ~/.pyenv/versions/<env_dir>/bin/activate <env_name> at least once to make it work

@taschini
Copy link

taschini commented Mar 6, 2018

Creating by hand the symbolic links within the environment bin directory to the conda and activate that you find in the conda base environment seems to fix the issue.

E.g.,

ln -s  ~/.pyenv/versions/miniconda3-latest/bin/activate ~/.pyenv/versions/miniconda3-latest/envs/test/bin/
ln -s  ~/.pyenv/versions/miniconda3-latest/bin/conda ~/.pyenv/versions/miniconda3-latest/envs/test/bin/

Edit This work-around is no longer necessary after #290.

@teake
Copy link

teake commented Mar 6, 2018

Running into this issue as well, though I'm using fish. For the fish shell, you have to either symlink or source <env_dir>/etc/fish/conf.d/conda.fish instead of <env_dir>/etc/profile.d/conda.sh.

@clbarnes
Copy link

clbarnes commented Mar 13, 2018

Even with #251 merged I'm still having this issue. I did

pyenv update
pyenv uninstall miniconda2-latest
pyenv uninstall miniconda3-latest

Then in a new terminal

pyenv install miniconda2-latest
pyenv virtualenv miniconda2-latest my-env
pyenv activate my-env

and got pyenv-virtualenv: version 'my-env' is not a virtualenv

When uninstalling miniconda2-latest again, pyenv does check that I want to remove my-env as well.

@teake
Copy link

teake commented Mar 20, 2018

#251 fixed activating an environment via conda:

pyenv install miniconda3-latest
pyenv activate miniconda3-latest
conda create --name myenv python
conda activate myenv

But I agree that doing this via pyenv-virtualenv should also work. (Though the above workflow is sufficient for me so I probably won't put in a PR).

@vrastogi
Copy link

The solution provided by @taschini fixes the problem and you can directly pyenv activate the conda virtual environment.

@taeke:
The problem with the solution you have (which probably already worked with bash) is that you cannot use facilities that pyenv provides, e.g., activating/deactivating an environment on changing directories.

@clbarnes
Copy link

@taschini 's answer is a workaround, not a solution. This is something pyenv should do internally, so this issue should be reopened until that's the case.

@vrastogi
Copy link

@clbarnes I agree that pyenv should provide a built-in solution for this and this thread should remain open to continue tracking the issue.

@apapanico
Copy link

apapanico commented May 9, 2018

Just to confirm to anyone visiting this thread. @taschini's solution:

alexp@iMac (main@Py3.6.4):~$ pyenv virtualenv miniconda3-4.3.30 test
...
alexp@iMac (main@Py3.6.4):~$ pyenv versions
  system
  3.6.4
  3.6.4/envs/main
  data8
* main (set by /Users/alexp/.python-version)
  miniconda3-4.3.30
  miniconda3-4.3.30/envs/test
  test
alexp@iMac (main@Py3.6.4):~$ pyenv activate test
pyenv-virtualenv: version `test' is not a virtualenv
alexp@iMac (main@Py3.6.4):~$ ln -s /usr/local/var/pyenv/versions/miniconda3-4.3.30/bin/conda /usr/local/var/pyenv/versions/test/bin/
alexp@iMac (main@Py3.6.4):~$ pyenv activate test
pyenv-virtualenv: version `test' is not a virtualenv
alexp@iMac (main@Py3.6.4):~$ ln -s /usr/local/var/pyenv/versions/miniconda3-4.3.30/bin/activate /usr/local/var/pyenv/versions/test/bin/
alexp@iMac (main@Py3.6.4):~$ pyenv activate test
alexp@iMac (test@PyInc.):~$ pyenv deactivate test
alexp@iMac (main@Py3.6.4):~$ 

It seems that both conda and activate are required.

I created a pyenv-virtualenv hook for this:

alexp@iMac (main@Py3.6.4):~$ pyenv hooks virtualenv
/usr/local/var/pyenv/pyenv.d/virtualenv/venv_hook.bash
# /usr/local/var/pyenv/pyenv.d/virtualenv/venv_hook.bash

after_virtualenv "BASE_VERSION=\"$(echo $VIRTUALENV_NAME | awk -F/ '{print $(NF-2)}')\""
after_virtualenv "VENVNAME=\"$(echo $VIRTUALENV_NAME | awk -F/ '{print $(NF)}')\""
after_virtualenv 'CONDA=${PYENV_ROOT}/versions/${BASE_VERSION}/bin/conda'
after_virtualenv 'ACTIVATE=${PYENV_ROOT}/versions/${BASE_VERSION}/bin/activate'

after_virtualenv 'if [[ $BASE_VERSION = *"conda"* ]]; then echo "...linking conda and activate"; fi'
after_virtualenv 'if [[ $BASE_VERSION = *"conda"* ]]; then ln -s ${CONDA} ${PYENV_ROOT}/versions/${VENVNAME}/bin/; fi'
after_virtualenv 'if [[ $BASE_VERSION = *"conda"* ]]; then ln -s ${ACTIVATE} ${PYENV_ROOT}/versions/${VENVNAME}/bin/; fi'

After the hook is installed:

alexp@iMac (main@Py3.6.4):~$ pyenv install miniconda3-4.3.30 
Installing Miniconda3-4.3.30.1-MacOSX-x86_64...
...
Installed Miniconda3-4.3.30.1-MacOSX-x86_64 to /usr/local/var/pyenv/versions/miniconda3-4.3.30

alexp@iMac (main@Py3.6.4):~$ pyenv versions
  system
  3.6.4
  3.6.4/envs/main
  data8
* main (set by /Users/alexp/.python-version)
  miniconda3-4.3.30
alexp@iMac (main@Py3.6.4):~$ pyenv virtualenv miniconda3-4.3.30 test
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate test
#
# To deactivate an active environment, use:
# > source deactivate
#

Requirement already satisfied: setuptools in /usr/local/var/pyenv/versions/miniconda3-4.3.30/envs/test/lib/python3.6/site-packages
Requirement already satisfied: pip in /usr/local/var/pyenv/versions/miniconda3-4.3.30/envs/test/lib/python3.6/site-packages
...linking conda and activate
alexp@iMac (main@Py3.6.4):~$ pyenv activate test
alexp@iMac (test@PyInc.):~$ pyenv which python
/usr/local/var/pyenv/versions/test/bin/python
alexp@iMac (test@PyInc.):~$ pyenv deactivate test
alexp@iMac (main@Py3.6.4):~$ 

@kondongx
Copy link

Creating by hand the symbolic links within the environment bin directory to the conda and activate that you find in the conda base environment seems to fix the issue.

E.g.,

ln -s  ~/.pyenv/versions/miniconda3-latest/bin/activate ~/.pyenv/versions/miniconda3-latest/envs/test/bin/
ln -s  ~/.pyenv/versions/miniconda3-latest/bin/conda ~/.pyenv/versions/miniconda3-latest/envs/test/bin/

fix my problem!

@feluxe
Copy link

feluxe commented Nov 11, 2018

I'm having the same issue. The hook doesn't work on my linux machine.

@apapanico
Copy link

Did linking work? Or is just the hook? I've found the hooks a bit tricky to program.

@kondongx
Copy link

Try downgrade miniconda to version-4.3.30:

pyenv activate miniconda3-latest
conda install conda=4.3.30

You can find it from #246.

@taschini
Copy link

#290 Solved my problem.

@jxxiao
Copy link

jxxiao commented Dec 14, 2018

@taschini 's answer is a workaround, not a solution. This is something pyenv should do internally, so this issue should be reopened until that's the case.

Even with #251 merged I'm still having this issue. I did

pyenv update
pyenv uninstall miniconda2-latest
pyenv uninstall miniconda3-latest

Then in a new terminal

pyenv install miniconda2-latest
pyenv virtualenv miniconda2-latest my-env
pyenv activate my-env

and got pyenv-virtualenv: version 'my-env' is not a virtualenv

When uninstalling miniconda2-latest again, pyenv does check that I want to remove my-env as well.

I got the same problem with you. I just confused why I can't activate a miniconda-virtualenv by pyenv activate.I hava to use conda activate.I found #290 It doesn't solve my problem.

@jimmywan
Copy link

@jxxiao #290 appears towork for me. I don't run pyenv activate, I used pyenv local and/or pyenv shell and they worked fine for me.

In fact, I never even use pyenv activate anymore. Doesn't seem to serve a useful purpose as an end user anymore.

@g6ai
Copy link

g6ai commented May 25, 2021

I'm using pyenv 2.0.0 on macOS 10.14.6. pyenv local still does not work for me out-of-box. To be exact, both conda and activate commands are not in the bin directory in env created by miniconda.

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

Successfully merging a pull request may close this issue.