Is it possible to activate virtualenv in Google-colab? (/bin/sh: 1: source: not found)

后端 未结 2 1850
北恋
北恋 2021-01-01 18:49

I am trying to install theano in Google Colab for testing. I have installed virtualenv and created an environment:

!pip3 install virtualenv
!vir         


        
2条回答
  •  我在风中等你
    2021-01-01 19:03

    Short answer, I don't believe it is possible, although you can always run

    !pip3 install theano
    

    I was able to activate the virtualenv, but I don't believe you can switch the current notebook to use the newly created virtualenv.

    !pip3 install virtualenv
    !virtualenv theanoEnv
    !echo '#!/bin/bash \n . ./theanoEnv/bin/activate theanoEnv \n which python3'  > source_theanoEnv.sh && chmod +x source_theanoEnv.sh && ./source_theanoEnv.sh && which python3
    !which python3
    

    I have put "which python3" in 3 places and the results are

    /content/theanoEnv/bin/python3
    /usr/bin/python3
    /usr/bin/python3
    

    So it looks like the "activate" is only temporary and Colaboratory/Jupyter are using /usr/bin/python3 still

    Basically each ! command runs in its own shell, and Colaboratory does not know the environment changed

    I was hoping I could follow these steps https://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs/

    /content/theanoEnv/bin/pip3 install ipykernel
    /content/theanoEnv/bin/python3 -m ipykernel install --user --name=theanoEnv
    

    But I don't know what to set the kernel_class to

    %config IPKernelApp.kernel_class='???'
    

    Also, even if the above worked, I don't believe there is a way to restart the notebook to use the new kernel.

    Perhaps someone more versed in Jupyter/Colaboratory could explain if this would be possible.

提交回复
热议问题