20
$\begingroup$

What version of Python does Blender use and are other languages available? Also, does Python work the same in Blender as when you write console applications or when working with Pygame or are there any differences? If so, what are the main differences?

$\endgroup$
3
  • 1
    $\begingroup$ Would you care to narrow the scope of your question regarding what differences you will encounter? comparing pygame api to blender api is a rather broad topic and will require either a very long answer or very generalized but short response. $\endgroup$
    – zeffii
    Commented Aug 26, 2013 at 13:36
  • 1
    $\begingroup$ Python 2 is no longer supported, see: How to change the Python version that Blender uses? $\endgroup$
    – Aldrik
    Commented Aug 26, 2013 at 13:41
  • 1
    $\begingroup$ Also, does python work the same in blender --- this should really be its own question, its quite a large topic, I answered it but since deleted my post, best ask in a separate Q. $\endgroup$
    – ideasman42
    Commented Oct 6, 2013 at 17:50

4 Answers 4

12
$\begingroup$

Since Blender 2.5 only Python 3 is supported. From blender.org:

The Blender 2.5x versions feature a completely new Python API based on Python version 3.2, and is integrated deeply, used for generating Blender's GUI layouts, for import and export of external formats, and with access to all user-accessible data and functionality.

What changes across applications is the API - Application programming interface. So if you're used to pygame and console API, now you need to learn Blender API. So yes, the idea is the same, but the API is different.

Here's a Quickstart Introduction.
And here's the full API.

$\endgroup$
8
$\begingroup$

Blender only supports Python3 for scripting, and currently there are now plans to support other languages natively.


There are however a few ways to use other languages from Python.

Use CPython to Execute Other Languages

Its possible to generate CPython bytecode directly.

  • Hy (Lisp syntax for CPython runtime), This works quite well with Blender.
  • Mochi

Bridge CPython to Other Runtimes

  • Lupa (Lua/Python)
  • Lunatic (Lua/Python) not updated for Python3

Call out to other languages From CPython

You could also look into LLVMPy, PyOpenCL or Cuda for Python, see this answer: https://blender.stackexchange.com/a/3159/55

Execute external processes

Theres nothing special about this, you can simply write out some XML/JSON/ANYFORMAT file from Blender's Python API, then load that file into any other runtime as an external process. operate on it, then read the data back in.

In some cases this is useful, but often its more trouble then its worth to write & read the data back into Blender.


Though I really would recommend just learning Python syntax, while its possible to side-step this, most/all? solutions to do so are not 100%... (no auto-completion in the console for example), defining callbacks to give to Blender... this kind of integration you loose.

$\endgroup$
1
  • $\begingroup$ Is there any plans for JavaScript/node.js support? $\endgroup$
    – William
    Commented Oct 28, 2018 at 14:10
7
$\begingroup$

Besides Python 3.x Blender supports:

  • GLSL OpenGL Shading Language which also supported in the game engine for materials or postprocessing
    (compiled at runtime by the OpenGL driver)

and

$\endgroup$
2
  • $\begingroup$ Doesn't glsl code need to be compiled into blender at build time, rather that being added by a user at run time? Which would make it comparable to using C/C++ $\endgroup$
    – sambler
    Commented Aug 27, 2013 at 2:06
  • $\begingroup$ @sambler I first discovered GLSL here blender.stackexchange.com/questions/1335/… (linked .blend file in the last line of the post). The results I had are shown here: blender.stackexchange.com/questions/2561/… the shader worked without compilation like a custom OSL shader. $\endgroup$
    – stacker
    Commented Aug 27, 2013 at 6:24
4
$\begingroup$

Blender 2.5 and above use python 3 but latest versions of Blender 2.6x utilize python 3.3 as the main scripting language. See the Blender API documentation. Blender Education & Help has more details if you are new to Blender.

Blender comes with CPython bundled, it is mostly the same default package that you might otherwise get from the python.org downloads, minus a few modules.

The Blender API is significantly different to pygame, but if you are comfortable with Python programming that won't be an obstacle.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .