You probably use Google Colaboratory to render your blender scenes and animations.
But in some cases like an animation that has a fluid simulation. you may not be able to render your animation on google colab. Because the cache files could go up to gigabytes of data and that much data takes forever to be uploaded to your google drive. and pain is that if you do that and then the render completes and you see the result and you are like: “Oh My God, I need to change something” and then you have to start again and waste a lot of time.
So, Here’s the solution.
Set up a google colab notebook and copy this code below to the first cell.
!wget https://download.blender.org/release/Blender2.92/blender-2.92.0-linux64.tar.xz !tar xf blender-2.92.0-linux64.tar.xz !apt install libboost-all-dev !apt install libgl1-mesa-dev from google.colab import drive drive.mount('/gdrive')
This will download and install Blender 2.92 (The stable release right now, you can change it to the version you like) and connect your google drive to google colab so the colab has access to your blender files and can save the rendered files there.
Now You need the the last cell code to run the blender.
filename = '/gdrive/MyDrive/BlenderFileName' !sudo ./blender-2.92.0-linux64/blender -b $filename -noaudio -P '/gdrive/MyDrive/PythonScriptFileName' -E 'CYCLES' -s 1 -e 250 -a
For The Python Script, You Need This.
import bpy bpy.ops.fluid.bake_all() def enable_gpus(device_type, use_cpus=False): preferences = bpy.context.preferences cycles_preferences = preferences.addons["cycles"].preferences cuda_devices, opencl_devices = cycles_preferences.get_devices() if device_type == "CUDA": devices = cuda_devices elif device_type == "OPENCL": devices = opencl_devices else: raise RuntimeError("Unsupported device type") activated_gpus =  for device in devices: if device.type == "CPU": device.use = use_cpus else: device.use = True activated_gpus.append(device.name) cycles_preferences.compute_device_type = device_type bpy.context.scene.cycles.device = "GPU" return activated_gpus enable_gpus("CUDA")
This code will bake the fluid simulation and ensure that we are rendering on GPU so we render much faster.
That’s all for baking the fluid simulation on google colab.