Skip to content

Instantly share code, notes, and snippets.

@donmahallem
Last active September 24, 2023 02:29
Show Gist options
  • Save donmahallem/a05100077ec1327268f28f0b2bd8da60 to your computer and use it in GitHub Desktop.
Save donmahallem/a05100077ec1327268f28f0b2bd8da60 to your computer and use it in GitHub Desktop.

Run Blender on Google Colab

Please Read

This is a automatically updated GIST copied from this repository. If you have any issues, suggestions or improvements please file those to that repository! It's far easier to keep track of conversations in their own dedicated issues/PRs.

Instructions

Please refer to the repositories instructions! For a quick start click the following badge: Open In Colab

{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "blender_script.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "MNd7jnnSkuUD",
"colab_type": "text"
},
"source": [
"#Setup\n",
"Specify your desired blender version and the path to your blend file within google drive.\n",
"\n",
"###Info\n",
"If you do need more information on parameters etc. look here: [Blender CLI Wiki](https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "8dFNjYGTgNjR",
"colab_type": "code",
"colab": {}
},
"source": [
"#@title Setup\n",
"#@markdown Please configure your setup\n",
"\n",
"blender_version = 'blender2.91.2' #@param [\"blender2.80\", \"blender2.81\", \"blender2.82\", \"blender2.83\", \"blender2.90.1\", \"blender2.91.2\"] {allow-input: false}\n",
"path_to_blend = 'path/to/blend.blend' #@param {type: \"string\"}\n",
"output_path = 'output/dir/in/drive/output####.png' #@param {type: \"string\"}\n",
"gpu_enabled = True #@param {type:\"boolean\"}\n",
"cpu_enabled = False #@param {type:\"boolean\"}\n",
"#@markdown ---\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "GPJ9fmoB6PWM",
"colab_type": "code",
"colab": {}
},
"source": [
"if blender_version == \"blender2.80\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.80/blender-2.80-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.81\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.81/blender-2.81-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.82\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.82/blender-2.82-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.83\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.83/blender-2.83.0-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.90.1\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.90/blender-2.90.1-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.91.2\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.91/blender-2.91.2-linux64.tar.xz\""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "OQ54OjLVjb26",
"colab_type": "code",
"colab": {}
},
"source": [
"!mkdir $blender_version\n",
"if blender_version == \"blender2.81\" or \"blender2.80\":\n",
" !wget -O '{blender_version}.tar.bz2' -nc $download_path\n",
" !tar -xf '{blender_version}.tar.bz2' -C ./$blender_version --strip-components=1\n",
"else:\n",
" !wget -O '{blender_version}.tar.xz' -nc $download_path\n",
" !tar xf '{blender_version}.tar.xz' -C ./$blender_version --strip-components=1\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "s3uIDMZLbYOE",
"colab_type": "text"
},
"source": [
"This Block is required as some weird behaviors with libtcmalloc appeared in the colab VM"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h6vohA2q2BDF",
"colab_type": "code",
"colab": {}
},
"source": [
"import os\n",
"\n",
"os.environ[\"LD_PRELOAD\"] = \"\"\n",
"\n",
"!apt update\n",
"!apt remove libtcmalloc-minimal4\n",
"!apt install libtcmalloc-minimal4\n",
"os.environ[\"LD_PRELOAD\"] = \"/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4.3.0\"\n",
"\n",
"!echo $LD_PRELOAD"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "UUwwvaq5BxzN",
"colab_type": "text"
},
"source": [
"Unpack and move blender"
]
},
{
"cell_type": "code",
"metadata": {
"id": "RU3p_G4hDk97",
"colab_type": "code",
"colab": {}
},
"source": [
"!apt install libboost-all-dev\n",
"!apt install libgl1-mesa-dev\n",
"!apt install libglu1-mesa libsm-dev"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Wh4i8msvAanq",
"colab_type": "text"
},
"source": [
"Required for Blender to use the GPU as expected"
]
},
{
"cell_type": "code",
"metadata": {
"id": "30Tv3lIeVaC6",
"colab_type": "code",
"colab": {}
},
"source": [
"data = \"import re\\n\"+\\\n",
" \"import bpy\\n\"+\\\n",
" \"scene = bpy.context.scene\\n\"+\\\n",
" \"scene.cycles.device = 'GPU'\\n\"+\\\n",
" \"prefs = bpy.context.preferences\\n\"+\\\n",
" \"prefs.addons['cycles'].preferences.get_devices()\\n\"+\\\n",
" \"cprefs = prefs.addons['cycles'].preferences\\n\"+\\\n",
" \"print(cprefs)\\n\"+\\\n",
" \"# Attempt to set GPU device types if available\\n\"+\\\n",
" \"for compute_device_type in ('CUDA', 'OPENCL', 'NONE'):\\n\"+\\\n",
" \" try:\\n\"+\\\n",
" \" cprefs.compute_device_type = compute_device_type\\n\"+\\\n",
" \" print('Device found',compute_device_type)\\n\"+\\\n",
" \" break\\n\"+\\\n",
" \" except TypeError:\\n\"+\\\n",
" \" pass\\n\"+\\\n",
" \"#for scene in bpy.data.scenes:\\n\"+\\\n",
" \"# scene.render.tile_x = 64\\n\"+\\\n",
" \"# scene.render.tile_y = 64\\n\"+\\\n",
" \"# Enable all CPU and GPU devices\\n\"+\\\n",
" \"for device in cprefs.devices:\\n\"+\\\n",
" \" if not re.match('intel', device.name, re.I):\\n\"+\\\n",
" \" print('Activating',device)\\n\"+\\\n",
" \" device.use = \"+str(gpu_enabled)+\"\\n\"+\\\n",
" \" else:\\n\"+\\\n",
" \" device.use = \"+str(cpu_enabled)+\"\\n\"\n",
"with open('setgpu.py', 'w') as f:\n",
" f.write(data)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "QRzNmiHN8Xr0",
"colab_type": "code",
"colab": {}
},
"source": [
"from google.colab import drive\n",
"drive.mount('/gdrive')"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "RPiQkHVbCDu2",
"colab_type": "text"
},
"source": [
"Use this if you want to render all Frames\n",
"\n",
"Use -s to speficy the start frame.\n",
"eg: -s 10\n",
"\n",
"Use -e to speficy the end frame.\n",
"eg: -e 20\n",
"\n",
"**THE ORDER IS IMPORTANT. BOTH -s AND -e MUST BE SPEFICIED BEFORE -a**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Fpk2w3yM8XqQ",
"colab_type": "code",
"colab": {}
},
"source": [
"!sudo ./$blender_version/blender -P './setgpu.py' -b '/gdrive/My Drive/{path_to_blend}' -E CYCLES -o '/gdrive/My Drive/{output_path}' -a"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "qmZg_8Eylgxe",
"colab_type": "text"
},
"source": [
"Use to render a single frame.\n",
"Specify the frame with -f *frame_number*"
]
},
{
"cell_type": "code",
"metadata": {
"id": "VFVx8omJCGBN",
"colab_type": "code",
"colab": {}
},
"source": [
"!sudo ./$blender_version/blender -P 'setgpu.py' -b '/gdrive/My Drive/{path_to_blend}' -P 'setgpu.py' -o '/gdrive/My Drive/{output_path}' -f 1"
],
"execution_count": 0,
"outputs": []
}
]
}
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "blender_script.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "MNd7jnnSkuUD",
"colab_type": "text"
},
"source": [
"#Setup\n",
"Specify your desired blender version and the path to your blend file within google drive or colab local storage.\n",
"\n",
"###Info\n",
"If you do need more information on parameters etc. look here: [Blender CLI Wiki](https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "8dFNjYGTgNjR",
"colab_type": "code",
"colab": {}
},
"source": [
"#@title Setup\n",
"#@markdown Please configure your setup\n",
"\n",
"blender_version = 'blender2.91.2' #@param [\"blender2.80\", \"blender2.81\", \"blender2.82\", \"blender2.83\", \"blender2.90.1\", \"blender2.91.2\"] {allow-input: false}\n",
"#@markdown You can right click a file and click copy path\n",
"path_to_blend = '/content/blendfile.blend' #@param {type: \"string\"}\n",
"output_path = '/content/output' #@param {type: \"string\"}\n",
"gpu_enabled = True #@param {type:\"boolean\"}\n",
"cpu_enabled = False #@param {type:\"boolean\"}\n",
"use_drive = False #@param {type:\"boolean\"}\n",
"#@markdown ---\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "QRzNmiHN8Xr0",
"colab_type": "code",
"colab": {}
},
"source": [
"if use_drive:\n",
" from google.colab import drive\n",
" drive.mount('/content/drive')\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "GPJ9fmoB6PWM",
"colab_type": "code",
"colab": {}
},
"source": [
"if blender_version == \"blender2.80\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.80/blender-2.80-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.81\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.81/blender-2.81-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.82\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.82/blender-2.82-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.83\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.83/blender-2.83.0-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.90.1\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.90/blender-2.90.1-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.91.2\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.91/blender-2.91.2-linux64.tar.xz\""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "OQ54OjLVjb26",
"colab_type": "code",
"colab": {}
},
"source": [
"!mkdir $blender_version\n",
"if blender_version == \"blender2.81\" or \"blender2.80\":\n",
" !wget -O '{blender_version}.tar.bz2' -nc $download_path\n",
" !tar -xf '{blender_version}.tar.bz2' -C ./$blender_version --strip-components=1\n",
"else:\n",
" !wget -O '{blender_version}.tar.xz' -nc $download_path\n",
" !tar xf '{blender_version}.tar.xz' -C ./$blender_version --strip-components=1\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "s3uIDMZLbYOE",
"colab_type": "text"
},
"source": [
"This Block is required as some weird behaviors with libtcmalloc appeared in the colab VM"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h6vohA2q2BDF",
"colab_type": "code",
"colab": {}
},
"source": [
"import os\n",
"\n",
"os.environ[\"LD_PRELOAD\"] = \"\"\n",
"\n",
"!apt update\n",
"!apt remove libtcmalloc-minimal4\n",
"!apt install libtcmalloc-minimal4\n",
"os.environ[\"LD_PRELOAD\"] = \"/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4.3.0\"\n",
"\n",
"!echo $LD_PRELOAD"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "UUwwvaq5BxzN",
"colab_type": "text"
},
"source": [
"Unpack and move blender"
]
},
{
"cell_type": "code",
"metadata": {
"id": "RU3p_G4hDk97",
"colab_type": "code",
"colab": {}
},
"source": [
"!apt install libboost-all-dev\n",
"!apt install libgl1-mesa-dev\n",
"!apt install libglu1-mesa libsm-dev"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Wh4i8msvAanq",
"colab_type": "text"
},
"source": [
"Required for Blender to use the GPU as expected"
]
},
{
"cell_type": "code",
"metadata": {
"id": "30Tv3lIeVaC6",
"colab_type": "code",
"colab": {}
},
"source": [
"data = \"import re\\n\"+\\\n",
" \"import bpy\\n\"+\\\n",
" \"scene = bpy.context.scene\\n\"+\\\n",
" \"scene.cycles.device = 'GPU'\\n\"+\\\n",
" \"prefs = bpy.context.preferences\\n\"+\\\n",
" \"prefs.addons['cycles'].preferences.get_devices()\\n\"+\\\n",
" \"cprefs = prefs.addons['cycles'].preferences\\n\"+\\\n",
" \"print(cprefs)\\n\"+\\\n",
" \"# Attempt to set GPU device types if available\\n\"+\\\n",
" \"for compute_device_type in ('CUDA', 'OPENCL', 'NONE'):\\n\"+\\\n",
" \" try:\\n\"+\\\n",
" \" cprefs.compute_device_type = compute_device_type\\n\"+\\\n",
" \" print('Device found',compute_device_type)\\n\"+\\\n",
" \" break\\n\"+\\\n",
" \" except TypeError:\\n\"+\\\n",
" \" pass\\n\"+\\\n",
" \"#for scene in bpy.data.scenes:\\n\"+\\\n",
" \"# scene.render.tile_x = 64\\n\"+\\\n",
" \"# scene.render.tile_y = 64\\n\"+\\\n",
" \"# Enable all CPU and GPU devices\\n\"+\\\n",
" \"for device in cprefs.devices:\\n\"+\\\n",
" \" if not re.match('intel', device.name, re.I):\\n\"+\\\n",
" \" print('Activating',device)\\n\"+\\\n",
" \" device.use = \"+str(gpu_enabled)+\"\\n\"+\\\n",
" \" else:\\n\"+\\\n",
" \" device.use = \"+str(cpu_enabled)+\"\\n\"\n",
"with open('setgpu.py', 'w') as f:\n",
" f.write(data)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "RPiQkHVbCDu2",
"colab_type": "text"
},
"source": [
"Use this if you want to render all Frames\n",
"\n",
"Use -s to speficy the start frame.\n",
"eg: -s 10\n",
"\n",
"Use -e to speficy the end frame.\n",
"eg: -e 20\n",
"\n",
"**THE ORDER IS IMPORTANT. BOTH -s AND -e MUST BE SPEFICIED BEFORE -a**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h9xSisNXBIbH",
"colab_type": "code",
"colab": {}
},
"source": [
"#@title Render Setup\r\n",
"#@markdow\r\n",
"whatToRender = 'renderOneFrame' #@param [\"renderOneFrame\", \"renderAllFrame\", \"renderWithinRange\"] {allow-input: false}\r\n",
"#@markdown StartFrame = the frame you want to start with or the frame number for the renderOneFrame option\r\n",
"startFrame = 1#@param {type: \"integer\"}\r\n",
"endFrame = 20 #@param {type: \"integer\"}"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "BIk15rdnCuVu",
"colab_type": "code",
"colab": {}
},
"source": [
"if whatToRender == 'renderOneFrame':\r\n",
" !sudo ./$blender_version/blender -P 'setgpu.py' -b '{path_to_blend}' -P 'setgpu.py' -o '{output_path}' -f {startFrame}\r\n",
"elif whatToRender == 'renderAllFrame':\r\n",
" !sudo ./$blender_version/blender -P './setgpu.py' -b '{path_to_blend}' -E CYCLES -o '{output_path}' -a\r\n",
"elif whatToRender == 'renderWithinRange':\r\n",
" !sudo ./$blender_version/blender -P './setgpu.py' -b '{path_to_blend}' -E CYCLES -o '{output_path}' -s {startFrame} -e {endFrame} -a"
],
"execution_count": null,
"outputs": []
}
]
}
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "blender_script.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "MNd7jnnSkuUD",
"colab_type": "text"
},
"source": [
"#Setup\n",
"Specify your desired blender version and the path to your blend file within google drive or colab local storage.\n",
"\n",
"###Info\n",
"If you do need more information on parameters etc. look here: [Blender CLI Wiki](https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "8dFNjYGTgNjR",
"colab_type": "code",
"colab": {}
},
"source": [
"#@title Setup\n",
"#@markdown Please configure your setup\n",
"\n",
"blender_version = 'blender2.91.2' #@param [\"blender2.80\", \"blender2.81\", \"blender2.82\", \"blender2.83\", \"blender2.90.1\", \"blender2.91.2\"] {allow-input: false}\n",
"#@markdown You can right click a file and click copy path\n",
"path_to_blend = '/content/blendfile.blend' #@param {type: \"string\"}\n",
"output_path = '/content/output' #@param {type: \"string\"}\n",
"gpu_enabled = True #@param {type:\"boolean\"}\n",
"cpu_enabled = False #@param {type:\"boolean\"}\n",
"use_drive = False #@param {type:\"boolean\"}\n",
"#@markdown ---\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "QRzNmiHN8Xr0",
"colab_type": "code",
"colab": {}
},
"source": [
"if use_drive:\n",
" from google.colab import drive\n",
" drive.mount('/content/drive')\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "GPJ9fmoB6PWM",
"colab_type": "code",
"colab": {}
},
"source": [
"if blender_version == \"blender2.80\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.80/blender-2.80-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.81\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.81/blender-2.81-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.82\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.82/blender-2.82-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.83\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.83/blender-2.83.0-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.90.1\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.90/blender-2.90.1-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.91.2\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.91/blender-2.91.2-linux64.tar.xz\""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "OQ54OjLVjb26",
"colab_type": "code",
"colab": {}
},
"source": [
"!mkdir $blender_version\n",
"if blender_version == \"blender2.81\" or \"blender2.80\":\n",
" !wget -O '{blender_version}.tar.bz2' -nc $download_path\n",
" !tar -xf '{blender_version}.tar.bz2' -C ./$blender_version --strip-components=1\n",
"else:\n",
" !wget -O '{blender_version}.tar.xz' -nc $download_path\n",
" !tar xf '{blender_version}.tar.xz' -C ./$blender_version --strip-components=1\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "s3uIDMZLbYOE",
"colab_type": "text"
},
"source": [
"This Block is required as some weird behaviors with libtcmalloc appeared in the colab VM"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h6vohA2q2BDF",
"colab_type": "code",
"colab": {}
},
"source": [
"import os\n",
"\n",
"os.environ[\"LD_PRELOAD\"] = \"\"\n",
"\n",
"!apt update\n",
"!apt remove libtcmalloc-minimal4\n",
"!apt install libtcmalloc-minimal4\n",
"os.environ[\"LD_PRELOAD\"] = \"/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4.3.0\"\n",
"\n",
"!echo $LD_PRELOAD"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "UUwwvaq5BxzN",
"colab_type": "text"
},
"source": [
"Unpack and move blender"
]
},
{
"cell_type": "code",
"metadata": {
"id": "RU3p_G4hDk97",
"colab_type": "code",
"colab": {}
},
"source": [
"!apt install libboost-all-dev\n",
"!apt install libgl1-mesa-dev\n",
"!apt install libglu1-mesa libsm-dev"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Wh4i8msvAanq",
"colab_type": "text"
},
"source": [
"Required for Blender to use the GPU as expected"
]
},
{
"cell_type": "code",
"metadata": {
"id": "30Tv3lIeVaC6",
"colab_type": "code",
"colab": {}
},
"source": [
"data = \"import re\\n\"+\\\n",
" \"import bpy\\n\"+\\\n",
" \"scene = bpy.context.scene\\n\"+\\\n",
" \"scene.cycles.device = 'GPU'\\n\"+\\\n",
" \"prefs = bpy.context.preferences\\n\"+\\\n",
" \"prefs.addons['cycles'].preferences.get_devices()\\n\"+\\\n",
" \"cprefs = prefs.addons['cycles'].preferences\\n\"+\\\n",
" \"print(cprefs)\\n\"+\\\n",
" \"# Attempt to set GPU device types if available\\n\"+\\\n",
" \"for compute_device_type in ('CUDA', 'OPENCL', 'NONE'):\\n\"+\\\n",
" \" try:\\n\"+\\\n",
" \" cprefs.compute_device_type = compute_device_type\\n\"+\\\n",
" \" print('Device found',compute_device_type)\\n\"+\\\n",
" \" break\\n\"+\\\n",
" \" except TypeError:\\n\"+\\\n",
" \" pass\\n\"+\\\n",
" \"#for scene in bpy.data.scenes:\\n\"+\\\n",
" \"# scene.render.tile_x = 64\\n\"+\\\n",
" \"# scene.render.tile_y = 64\\n\"+\\\n",
" \"# Enable all CPU and GPU devices\\n\"+\\\n",
" \"for device in cprefs.devices:\\n\"+\\\n",
" \" if not re.match('intel', device.name, re.I):\\n\"+\\\n",
" \" print('Activating',device)\\n\"+\\\n",
" \" device.use = \"+str(gpu_enabled)+\"\\n\"+\\\n",
" \" else:\\n\"+\\\n",
" \" device.use = \"+str(cpu_enabled)+\"\\n\"\n",
"with open('setgpu.py', 'w') as f:\n",
" f.write(data)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "RPiQkHVbCDu2",
"colab_type": "text"
},
"source": [
"Use this if you want to render all Frames\n",
"\n",
"Use -s to speficy the start frame.\n",
"eg: -s 10\n",
"\n",
"Use -e to speficy the end frame.\n",
"eg: -e 20\n",
"\n",
"**THE ORDER IS IMPORTANT. BOTH -s AND -e MUST BE SPEFICIED BEFORE -a**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h9xSisNXBIbH",
"colab_type": "code",
"colab": {}
},
"source": [
"#@title Render Setup\r\n",
"#@markdown\r\n",
"whatToRender = 'renderOneFrame' #@param [\"renderOneFrame\", \"renderAllFrame\", \"renderWithinRange\"] {allow-input: false}\r\n",
"#@markdown StartFrame = the frame you want to start with or the frame number for the renderOneFrame option\r\n",
"startFrame = 1#@param {type: \"integer\"}\r\n",
"endFrame = 20 #@param {type: \"integer\"}"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "BIk15rdnCuVu",
"colab_type": "code",
"colab": {}
},
"source": [
"if whatToRender == 'renderOneFrame':\r\n",
" !sudo ./$blender_version/blender -P 'setgpu.py' -b '{path_to_blend}' -P 'setgpu.py' -o '{output_path}' -f {startFrame}\r\n",
"elif whatToRender == 'renderAllFrame':\r\n",
" !sudo ./$blender_version/blender -P './setgpu.py' -b '{path_to_blend}' -E CYCLES -o '{output_path}' -a\r\n",
"elif whatToRender == 'renderWithinRange':\r\n",
" !sudo ./$blender_version/blender -P './setgpu.py' -b '{path_to_blend}' -E CYCLES -o '{output_path}' -s {startFrame} -e {endFrame} -a"
],
"execution_count": null,
"outputs": []
}
]
}
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "blender_script.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "MNd7jnnSkuUD",
"colab_type": "text"
},
"source": [
"#Setup\n",
"Specify your desired blender version and the path to your blend file within google drive or colab local storage.\n",
"\n",
"###Info\n",
"If you do need more information on parameters etc. look here: [Blender CLI Wiki](https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "8dFNjYGTgNjR",
"colab_type": "code",
"colab": {}
},
"source": [
"#@title Setup\n",
"#@markdown Please configure your setup\n",
"\n",
"blender_version = 'blender2.91.2' #@param [\"blender2.80\", \"blender2.81\", \"blender2.82\", \"blender2.83\", \"blender2.90.1\", \"blender2.91.2\"] {allow-input: false}\n",
"#@markdown You can right click a file and click copy path\n",
"path_to_blend = '/content/blendfile.blend' #@param {type: \"string\"}\n",
"output_path = '/content/output' #@param {type: \"string\"}\n",
"gpu_enabled = True #@param {type:\"boolean\"}\n",
"cpu_enabled = False #@param {type:\"boolean\"}\n",
"use_drive = False #@param {type:\"boolean\"}\n",
"#@markdown ---\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "QRzNmiHN8Xr0",
"colab_type": "code",
"colab": {}
},
"source": [
"if use_drive:\n",
" from google.colab import drive\n",
" drive.mount('/content/drive')\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "GPJ9fmoB6PWM",
"colab_type": "code",
"colab": {}
},
"source": [
"if blender_version == \"blender2.80\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.80/blender-2.80-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.81\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.81/blender-2.81-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.82\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.82/blender-2.82-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.83\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.83/blender-2.83.0-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.90.1\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.90/blender-2.90.1-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.91.2\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.91/blender-2.91.2-linux64.tar.xz\""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "OQ54OjLVjb26",
"colab_type": "code",
"colab": {}
},
"source": [
"!mkdir $blender_version\n",
"if blender_version == \"blender2.81\" or \"blender2.80\":\n",
" !wget -O '{blender_version}.tar.bz2' -nc $download_path\n",
" !tar -xf '{blender_version}.tar.bz2' -C ./$blender_version --strip-components=1\n",
"else:\n",
" !wget -O '{blender_version}.tar.xz' -nc $download_path\n",
" !tar xf '{blender_version}.tar.xz' -C ./$blender_version --strip-components=1\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "s3uIDMZLbYOE",
"colab_type": "text"
},
"source": [
"This Block is required as some weird behaviors with libtcmalloc appeared in the colab VM"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h6vohA2q2BDF",
"colab_type": "code",
"colab": {}
},
"source": [
"import os\n",
"\n",
"os.environ[\"LD_PRELOAD\"] = \"\"\n",
"\n",
"!apt update\n",
"!apt remove libtcmalloc-minimal4\n",
"!apt install libtcmalloc-minimal4\n",
"os.environ[\"LD_PRELOAD\"] = \"/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4.3.0\"\n",
"\n",
"!echo $LD_PRELOAD"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "UUwwvaq5BxzN",
"colab_type": "text"
},
"source": [
"Unpack and move blender"
]
},
{
"cell_type": "code",
"metadata": {
"id": "RU3p_G4hDk97",
"colab_type": "code",
"colab": {}
},
"source": [
"!apt install libboost-all-dev\n",
"!apt install libgl1-mesa-dev\n",
"!apt install libglu1-mesa libsm-dev"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Wh4i8msvAanq",
"colab_type": "text"
},
"source": [
"Required for Blender to use the GPU as expected"
]
},
{
"cell_type": "code",
"metadata": {
"id": "30Tv3lIeVaC6",
"colab_type": "code",
"colab": {}
},
"source": [
"data = \"import re\\n\"+\\\n",
" \"import bpy\\n\"+\\\n",
" \"scene = bpy.context.scene\\n\"+\\\n",
" \"scene.cycles.device = 'GPU'\\n\"+\\\n",
" \"prefs = bpy.context.preferences\\n\"+\\\n",
" \"prefs.addons['cycles'].preferences.get_devices()\\n\"+\\\n",
" \"cprefs = prefs.addons['cycles'].preferences\\n\"+\\\n",
" \"print(cprefs)\\n\"+\\\n",
" \"# Attempt to set GPU device types if available\\n\"+\\\n",
" \"for compute_device_type in ('CUDA', 'OPENCL', 'NONE'):\\n\"+\\\n",
" \" try:\\n\"+\\\n",
" \" cprefs.compute_device_type = compute_device_type\\n\"+\\\n",
" \" print('Device found',compute_device_type)\\n\"+\\\n",
" \" break\\n\"+\\\n",
" \" except TypeError:\\n\"+\\\n",
" \" pass\\n\"+\\\n",
" \"#for scene in bpy.data.scenes:\\n\"+\\\n",
" \"# scene.render.tile_x = 64\\n\"+\\\n",
" \"# scene.render.tile_y = 64\\n\"+\\\n",
" \"# Enable all CPU and GPU devices\\n\"+\\\n",
" \"for device in cprefs.devices:\\n\"+\\\n",
" \" if not re.match('intel', device.name, re.I):\\n\"+\\\n",
" \" print('Activating',device)\\n\"+\\\n",
" \" device.use = \"+str(gpu_enabled)+\"\\n\"+\\\n",
" \" else:\\n\"+\\\n",
" \" device.use = \"+str(cpu_enabled)+\"\\n\"\n",
"with open('setgpu.py', 'w') as f:\n",
" f.write(data)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "RPiQkHVbCDu2",
"colab_type": "text"
},
"source": [
"Use this if you want to render all Frames\n",
"\n",
"Use -s to speficy the start frame.\n",
"eg: -s 10\n",
"\n",
"Use -e to speficy the end frame.\n",
"eg: -e 20\n",
"\n",
"**THE ORDER IS IMPORTANT. BOTH -s AND -e MUST BE SPEFICIED BEFORE -a**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h9xSisNXBIbH",
"colab_type": "code",
"colab": {}
},
"source": [
"#@title Render Setup\r\n",
"#@markdown\r\n",
"whatToRender = 'renderOneFrame' #@param [\"renderOneFrame\", \"renderAllFrame\", \"renderWithinRange\"] {allow-input: false}\r\n",
"#@markdown StartFrame = the frame you want to start with or the frame number for the renderOneFrame option\r\n",
"startFrame = 1#@param {type: \"integer\"}\r\n",
"endFrame = 20 #@param {type: \"integer\"}"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "BIk15rdnCuVu",
"colab_type": "code",
"colab": {}
},
"source": [
"if whatToRender == 'renderOneFrame':\r\n",
" !sudo ./$blender_version/blender -P 'setgpu.py' -b '{path_to_blend}' -P 'setgpu.py' -o '{output_path}' -f {startFrame}\r\n",
"elif whatToRender == 'renderAllFrame':\r\n",
" !sudo ./$blender_version/blender -P './setgpu.py' -b '{path_to_blend}' -E CYCLES -o '{output_path}' -a\r\n",
"elif whatToRender == 'renderWithinRange':\r\n",
" !sudo ./$blender_version/blender -P './setgpu.py' -b '{path_to_blend}' -E CYCLES -o '{output_path}' -s {startFrame} -e {endFrame} -a"
],
"execution_count": null,
"outputs": []
}
]
}
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "blender_script.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "MNd7jnnSkuUD",
"colab_type": "text"
},
"source": [
"#Setup\n",
"Specify your desired blender version and the path to your blend file within google drive or colab local storage.\n",
"\n",
"###Info\n",
"If you do need more information on parameters etc. look here: [Blender CLI Wiki](https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "8dFNjYGTgNjR",
"colab_type": "code",
"colab": {}
},
"source": [
"#@title Setup\n",
"#@markdown Please configure your setup\n",
"\n",
"blender_version = 'blender2.91.2' #@param [\"blender2.80\", \"blender2.81\", \"blender2.82\", \"blender2.83\", \"blender2.90.1\", \"blender2.91.2\"] {allow-input: false}\n",
"#@markdown You can right click a file and click copy path\n",
"path_to_blend = '/content/blendfile.blend' #@param {type: \"string\"}\n",
"output_path = '/content/output' #@param {type: \"string\"}\n",
"gpu_enabled = True #@param {type:\"boolean\"}\n",
"cpu_enabled = False #@param {type:\"boolean\"}\n",
"use_drive = False #@param {type:\"boolean\"}\n",
"#@markdown ---\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "QRzNmiHN8Xr0",
"colab_type": "code",
"colab": {}
},
"source": [
"if use_drive:\n",
" from google.colab import drive\n",
" drive.mount('/content/drive')\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "GPJ9fmoB6PWM",
"colab_type": "code",
"colab": {}
},
"source": [
"if blender_version == \"blender2.80\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.80/blender-2.80-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.81\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.81/blender-2.81-linux-glibc217-x86_64.tar.bz2\"\n",
"elif blender_version == \"blender2.82\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.82/blender-2.82-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.83\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.83/blender-2.83.0-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.90.1\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.90/blender-2.90.1-linux64.tar.xz\"\n",
"elif blender_version == \"blender2.91.2\":\n",
" download_path=\"https://ftp.halifax.rwth-aachen.de/blender/release/Blender2.91/blender-2.91.2-linux64.tar.xz\""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "OQ54OjLVjb26",
"colab_type": "code",
"colab": {}
},
"source": [
"!mkdir $blender_version\n",
"if blender_version == \"blender2.81\" or \"blender2.80\":\n",
" !wget -O '{blender_version}.tar.bz2' -nc $download_path\n",
" !tar -xf '{blender_version}.tar.bz2' -C ./$blender_version --strip-components=1\n",
"else:\n",
" !wget -O '{blender_version}.tar.xz' -nc $download_path\n",
" !tar xf '{blender_version}.tar.xz' -C ./$blender_version --strip-components=1\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "s3uIDMZLbYOE",
"colab_type": "text"
},
"source": [
"This Block is required as some weird behaviors with libtcmalloc appeared in the colab VM"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h6vohA2q2BDF",
"colab_type": "code",
"colab": {}
},
"source": [
"import os\n",
"\n",
"os.environ[\"LD_PRELOAD\"] = \"\"\n",
"\n",
"!apt update\n",
"!apt remove libtcmalloc-minimal4\n",
"!apt install libtcmalloc-minimal4\n",
"os.environ[\"LD_PRELOAD\"] = \"/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4.3.0\"\n",
"\n",
"!echo $LD_PRELOAD"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "UUwwvaq5BxzN",
"colab_type": "text"
},
"source": [
"Unpack and move blender"
]
},
{
"cell_type": "code",
"metadata": {
"id": "RU3p_G4hDk97",
"colab_type": "code",
"colab": {}
},
"source": [
"!apt install libboost-all-dev\n",
"!apt install libgl1-mesa-dev\n",
"!apt install libglu1-mesa libsm-dev"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Wh4i8msvAanq",
"colab_type": "text"
},
"source": [
"Required for Blender to use the GPU as expected"
]
},
{
"cell_type": "code",
"metadata": {
"id": "30Tv3lIeVaC6",
"colab_type": "code",
"colab": {}
},
"source": [
"data = \"import re\\n\"+\\\n",
" \"import bpy\\n\"+\\\n",
" \"scene = bpy.context.scene\\n\"+\\\n",
" \"scene.cycles.device = 'GPU'\\n\"+\\\n",
" \"prefs = bpy.context.preferences\\n\"+\\\n",
" \"prefs.addons['cycles'].preferences.get_devices()\\n\"+\\\n",
" \"cprefs = prefs.addons['cycles'].preferences\\n\"+\\\n",
" \"print(cprefs)\\n\"+\\\n",
" \"# Attempt to set GPU device types if available\\n\"+\\\n",
" \"for compute_device_type in ('CUDA', 'OPENCL', 'NONE'):\\n\"+\\\n",
" \" try:\\n\"+\\\n",
" \" cprefs.compute_device_type = compute_device_type\\n\"+\\\n",
" \" print('Device found',compute_device_type)\\n\"+\\\n",
" \" break\\n\"+\\\n",
" \" except TypeError:\\n\"+\\\n",
" \" pass\\n\"+\\\n",
" \"#for scene in bpy.data.scenes:\\n\"+\\\n",
" \"# scene.render.tile_x = 64\\n\"+\\\n",
" \"# scene.render.tile_y = 64\\n\"+\\\n",
" \"# Enable all CPU and GPU devices\\n\"+\\\n",
" \"for device in cprefs.devices:\\n\"+\\\n",
" \" if not re.match('intel', device.name, re.I):\\n\"+\\\n",
" \" print('Activating',device)\\n\"+\\\n",
" \" device.use = \"+str(gpu_enabled)+\"\\n\"+\\\n",
" \" else:\\n\"+\\\n",
" \" device.use = \"+str(cpu_enabled)+\"\\n\"\n",
"with open('setgpu.py', 'w') as f:\n",
" f.write(data)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "RPiQkHVbCDu2",
"colab_type": "text"
},
"source": [
"Use this if you want to render all Frames\n",
"\n",
"Use -s to speficy the start frame.\n",
"eg: -s 10\n",
"\n",
"Use -e to speficy the end frame.\n",
"eg: -e 20\n",
"\n",
"**THE ORDER IS IMPORTANT. BOTH -s AND -e MUST BE SPEFICIED BEFORE -a**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h9xSisNXBIbH",
"colab_type": "code",
"colab": {}
},
"source": [
"#@title Render Setup\r\n",
"#@markdown\r\n",
"whatToRender = 'renderOneFrame' #@param [\"renderOneFrame\", \"renderAllFrame\", \"renderWithinRange\"] {allow-input: false}\r\n",
"#@markdown StartFrame = the frame you want to start with or the frame number for the renderOneFrame option\r\n",
"startFrame = 1#@param {type: \"integer\"}\r\n",
"endFrame = 20 #@param {type: \"integer\"}"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "BIk15rdnCuVu",
"colab_type": "code",
"colab": {}
},
"source": [
"if whatToRender == 'renderOneFrame':\r\n",
" !sudo ./$blender_version/blender -P 'setgpu.py' -b '{path_to_blend}' -P 'setgpu.py' -o '{output_path}' -f {startFrame}\r\n",
"elif whatToRender == 'renderAllFrame':\r\n",
" !sudo ./$blender_version/blender -P './setgpu.py' -b '{path_to_blend}' -E CYCLES -o '{output_path}' -a\r\n",
"elif whatToRender == 'renderWithinRange':\r\n",
" !sudo ./$blender_version/blender -P './setgpu.py' -b '{path_to_blend}' -E CYCLES -o '{output_path}' -s {startFrame} -e {endFrame} -a"
],
"execution_count": null,
"outputs": []
}
]
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@donmahallem
Copy link
Author

@gunboxstudios2020

Hi. If you are savvy you are free to provide updated Version links to this repo. The script above will update once I merge the pull request automatically. My plan was to put some time into it this weekend and atleast update the Version Selector to the most reason one.

@jujubeesloco
Copy link

@MasterHelix9
I don't think you need those instructions.
Below has been my solution. Taken from closed issues: donmahallem/colab_blender#1

----Rendering EEVEE headless------>
(Note: Replace CYCLES with BLENDER_EEVEE)

!apt-get install python-opengl -y

!apt install xvfb -y

!pip install pyvirtualdisplay

!pip install piglet

from pyvirtualdisplay import Display
Display().start()

@donmahallem
Copy link
Author

@gunboxstudios2020 and anyone else who wants 2.90(.1) support would you mind testing the changed script, before I merge it:
https://github.com/donmahallem/colab_blender/blob/blender_2.90.1/runblender.ipynb
and comment at:
donmahallem/colab_blender#11

@9helix
Copy link

9helix commented Oct 17, 2020

@MasterHelix9
I don't think you need those instructions.
Below has been my solution. Taken from closed issues: donmahallem/colab_blender#1

----Rendering EEVEE headless------>
(Note: Replace CYCLES with BLENDER_EEVEE)

!apt-get install python-opengl -y

!apt install xvfb -y

!pip install pyvirtualdisplay

!pip install piglet

from pyvirtualdisplay import Display
Display().start()

Where should I put that part of the code and/or how would the full code look like?

@donmahallem
Copy link
Author

@MasterHelix9 this part should be placed in a code cell anywhere before the actual rendering is invoked. So just add it at the very start.

@9helix
Copy link

9helix commented Oct 18, 2020

@MasterHelix9 this part should be placed in a code cell anywhere before the actual rendering is invoked. So just add it at the very start.
Should I then paste your code after that? Do I need to paste just the "Rendering Eevee headless" section at the beggining?

@jujubeesloco
Copy link

jujubeesloco commented Oct 18, 2020

@MasterHelix9

Just add it before this(the invoking of the render):

!sudo ./$blender_version/blender -P './setgpu.py' -b '/gdrive/My Drive/{path_to_blend}' -E CYCLES -o '/gdrive/My Drive/{output_path}' -a

‐------------

And remember to replace CYCLES with BLENDER_EEVEE in the above.

@9helix
Copy link

9helix commented Oct 18, 2020

@jujubeesloco @donmahallem
Thank you for your help!

@9helix
Copy link

9helix commented Oct 20, 2020

Is it possible to change active camera and scene while rendering?

@donmahallem
Copy link
Author

Absolutely. You just need to extend the the quoted python script and select programmatically the camera and scene you prefer

@9helix
Copy link

9helix commented Oct 21, 2020

Absolutely. You just need to extend the the quoted python script and select programmatically the camera and scene you prefer

@donmahallem What's the code to do that?

@donmahallem
Copy link
Author

@MasterHelix9 I would refer you to google, stack overflow and the current Blender Api Documentation.

It all depends on what you are trying to accomplish. Otherwise you would have to do that manually by rendering just the frames you need and switch out the file

@9helix
Copy link

9helix commented Oct 21, 2020

@donamhallem I have multiple cameras in my scene and they should render same frames but from different angles, so I need a way to switch between cameras inside google colab without having to change active camera in project file and reuploading it again every time. I found a command that can do that: bpy.context.scene.camera = bpy.data.objects["camera_name"] Do I need to import or install any extra modules to google colab for this to work?

@donmahallem
Copy link
Author

The only other way I see is switching the camera of the scene as described above or create multiple linked scenes with a camera for each one.

Imho: it's easier just to reupload the changed active camera imho and render everything twice as you multiply the render time anyway with the camera count.

@9helix
Copy link

9helix commented Oct 21, 2020

@donmahallem If I want to use this command: bpy.context.scene.camera = bpy.data.objects["camera_name"] do I need to install/import any extra modules (bpy) to the google colab?

@donmahallem
Copy link
Author

Afaik no.

For reference you can use the documentation linked above where you can look up available interfaces for any given blender version and which instructions to use.

In the gist above there is a section which uses and launches a small python script as well.

I am currently only on the phone and can only give coarse directions where you need to look. Try the script locally for switching the cams. Either embed it into the blend file(might be prone to issues) or queue it after the blend file loading with a '-P' cli argument.

From what I understood you want to do the easiest imho is still to render all frames for one camera. Switch active camera and render all frames again

@sukhmancs
Copy link

it didn't work just says ### there is no such file or directory
Screenshot (19)

@donmahallem
Copy link
Author

Please read the error message carefully.

Error: File format is not supported in file '/gdrive/My Drive/Blender_colabrender/magingrass.blend'

Are you sure your blend file is correct?

@sukhmancs
Copy link

sukhmancs commented Dec 28, 2020 via email

@donmahallem
Copy link
Author

As the error clearly states: blender can find the file but blender can't read it. I can't tell from here what is wrong with the file

@sukhmancs
Copy link

sukhmancs commented Dec 29, 2020 via email

Copy link

ghost commented Jan 26, 2021

How I can include the path to bake file in the drive, is there any specific keyword for that?

@donmahallem
Copy link
Author

Put all files into one folder on your local drive. Make all paths relative with blender, save and upload that folder. this way your paths to external files should be platform independant

Copy link

ghost commented Jan 26, 2021

Will see it in while.Thanks for the quick response :)

@nanlliu
Copy link

nanlliu commented Feb 10, 2021

i have revised it a bit for my own research purpose. can I make it public in Github (just want to get permission from you first).
really appreciate it!

@donmahallem

@donmahallem
Copy link
Author

@nanlliu if you have any improvements you are free to share them. This gist is an auto update of this repository. If you have any improvements you are invited to provide them as a Pull Request and contribute to the project.

@nanlliu
Copy link

nanlliu commented Feb 10, 2021

i didn't improve anything and it doesn't fulfill the same needs. it runs a program that uses blender. It is a program that generates a bunch of dataset called 'Clevr'.

@vonvanzu
Copy link

I tried to render in GPU new cycles x in Google Colab, but I can't, this message showed (some suggestions):

Blender 3.0.0 Alpha (hash 342cdb03ee06 built 2021-09-28 02:36:05)
F0929 13:02:02.627323 404 device.cpp:323] Device does not support queues.
*** Check failure stack trace: ***
@ 0x28cf58d (unknown)
@ 0x28d1493 (unknown)
@ 0x28cf11d (unknown)
@ 0x28d1d69 (unknown)
@ 0x28f07b0 ccl::Device::gpu_queue_create()
@ 0x2f82799 ccl::PathTraceWorkGPU::PathTraceWorkGPU()
@ 0x2f7dac4 ccl::PathTraceWork::create()
@ 0x2f787f2 (unknown)
@ 0x2f78b21 ccl::PathTrace::PathTrace()
@ 0x2eadbb4 ccl::Session::Session()
@ 0x2871f0d ccl::BlenderSession::create_session()
@ 0x2872b60 ccl::BlenderSession::reset_session()
@ 0x286a4fd (unknown)
@ 0x98da484 (unknown)
@ 0x989c180 _PyObject_MakeTpCall
@ 0x1035210 _PyEval_EvalFrameDefault
@ 0x102b33b (unknown)
@ 0x10328ed _PyEval_EvalFrameDefault
@ 0x102b33b (unknown)
@ 0x989bbdf PyVectorcall_Call
@ 0x1a8d828 (unknown)
@ 0x1a01466 (unknown)
@ 0x9247026 RE_engine_render
@ 0x924ab57 (unknown)
@ 0x924dbd0 (unknown)
@ 0x924e73c RE_RenderAnim
@ 0x1037c3c (unknown)
@ 0xac5dcc7 BLI_args_parse
@ 0xf24515 main
@ 0x7f2901d8cbf7 __libc_start_main
@ 0x103561c (unknown)
@ (nil) (unknown)

  • Maybe I have to try the paid version of Colab to avoid queues?

@exuanbo
Copy link

exuanbo commented Dec 15, 2021

I notice that there are some redundant files gitfile1.txt, gistfile2.txt etc.

That is because exuanbo/actions-deploy-gist@v1.0.4 introduces a bug causing the gist filename to be un empty string if gist_file_name is not provided. It is fixed in v1.1.2 and v1.

@donmahallem
Copy link
Author

@exuanbo Thanks for the info. Will try to clean this up asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment