is there any way to conditionally install python packages if the notebook is run in Google Colab vs anywhere else?
For example, if you have a notebook that requires some python package, but only want to !pip install mypackage when the notebook is being run in colab, is there some way to test for that? e.g.
if current_environment == 'Google Colab':
!pip install my_packages
I found the answer here. You can look for the colabtools folder.
%%bash
[[ ! -e /colabtools ]] && exit # Continue only if running on Google Colab
# Do Colab-only stuff here
!pip install my_packages
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