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
To install virtualenv, just use pip install virtualenv . To create a virtual environment directory with it, type virtualenv /path/to/directory . Activating and deactivating the virtual environment works the same way as it does for virtual environments in Python 3 (see above).
Basically each ! command runs in its own shell, and Colaboratory does not know the environment changed
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
!pip3 install virtualenv
!virtualenv theanoEnv
you can install theano in the environment by
!source /content/theanoEnv/bin/activate; pip3 install theano
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
!source /content/theanoEnv/bin/activate;
For example, to get a list of installed python packages (i.e. to run pip3 list
) in environment, run:
!source /content/theanoEnv/bin/activate; pip3 list
You can stitch multiple commands this way: (all of them will be executed in the same shell)
!source /content/theanoEnv/bin/activate; COMMAND1; COMMAND2; COMMAND3
You can check my notebook on Colab here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With