How can I run blender from command line or a python script without opening a GUI?

I’m interested in using Blender for producing images, 3d files, or calculating geometry on a server.

Can I make blender run a python script without opening a GUI?

If not, can I incorporate Blender’s python API into my own python script without running a GUI?

Answer

Command-line / subprocess

  • You can use subprocess to run blender (like any other application) from python.
  • Use the -b / --background switch to run blender in the backgroud (GUI-less).
  • Use the -P <filename> / --python <filename> switch to load desired python script.
    • Or use --python-console to run python from stdin.

Example: blender --background --python myscript.py

See: https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html

As module

This is an experimental feature and not enabled by default, but Blender can be compiled as a python module.

This allows ‘bpy’ to be imported from python or other applications/IDE’s which embed python

Attribution
Source : Link , Question Author : BenjaminGolder , Answer Author : brockmann

Leave a Comment