I am trying to install theano in Google Colab for testing. I have installed virtualenv
and created an environment:
!pip3 install virtualenv
!virtualenv theanoEnv
But am not able to activate the virtual environment even explicitly mentioned the location of 'activate' command.
!source /content/theanoEnv/bin/activate theanoEnv
Error Message is:
/bin/sh: 1: source: not found
Is it even possible to do?:
source /[SomeVirtualEnv]/bin/activate SomeVirtualEnv
I figured out a workaround for this. Since each shell is temporary, we stitch the environment activation command and the command to be executed in environment.
So after you do
you can install theano in the environment by
Since the environment contents are stored on disk in theanoEnv directory, it is preserved. But you need to activate it for each new shell. For every command you need to run in the environment, simply prefix it with
For example, to get a list of installed python packages (i.e. to run
pip3 list
) in environment, run:You can stitch multiple commands this way: (all of them will be executed in the same shell)
You can check my notebook on Colab here.
Short answer, I don't believe it is possible, although you can always run
I was able to activate the virtualenv, but I don't believe you can switch the current notebook to use the newly created virtualenv.
I have put "which python3" in 3 places and the results are
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/
But I don't know what to set the kernel_class to
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.