2

我正在尝试使用 google colab pro 提供的 GPU 在搅拌机中运行脚本。

我使用以下代码来安装和配置 Blender:

import os
os.environ["LD_PRELOAD"] = ""

!apt remove libtcmalloc-minimal4
!apt install libtcmalloc-minimal4

os.environ["LD_PRELOAD"] = "/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4.3.0"

!wget https://download.blender.org/release/Blender2.93/blender-2.93.0-linux-x64.tar.xz
!tar -xf blender-2.93.0-linux-x64.tar.xz

# if you still get any errors regarding LD_PRELOAD you can check whether a good path is applied (if the version of library has not changed)
!dpkg -L libtcmalloc-minimal4 

!ln -s /content/blender-2.93.0-stable+blender-v293-release.84da05a8b806-linux.x86_64-release/blender /usr/local/bin/blender
!blender -v

之后,我按如下方式运行我的脚本:

!blender -b -noaudio --python /content/code/generate_images.py -E CYCLES -a --cycles-device CUDA 

但它给出了以下错误:

Unable to open a display

脚本 generate_images.py 包含一系列操作(相机和灯光被创建,相机沿着预定义位置的轨迹移动),并且在相机的每个位置渲染图像。我注意到当到达以下行时会出现错误:

bpy.ops.render.render(write_still=True)

该脚本在我的笔记本电脑上本地完美运行。你对这个问题有任何线索吗?

4

2 回答 2

1

我能够通过添加来解决这个问题

bpy.context.scene.render.engine = 'CYCLES'

在要在 Blender 中执行的 python 脚本中,就在之前

bpy.ops.render.render(write_still=True)
于 2022-01-06T13:09:57.650 回答
0

您应该先在机器上渲染一次,然后再将其带到 colab 进行渲染

于 2022-01-27T00:57:44.403 回答