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?
4 Answers
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.
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.
Bridge CPython to Other Runtimes
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.
-
$\begingroup$ Is there any plans for JavaScript/node.js support? $\endgroup$– WilliamCommented Oct 28, 2018 at 14:10
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
- OSL - Open Shading Language for Cycles Shaders
(compiled at runtime by Blender's bundled OSL library)
-
$\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$– samblerCommented 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$– stackerCommented Aug 27, 2013 at 6:24
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.
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$