[Bf-python] Python in Blender for Pycon

Willian Padovani Germano wpgermano at gmail.com
Mon Nov 16 17:47:59 CET 2009


Hi,

Since Joe answered about Blender 2.5 already, I'll try to help with 
older stuff up to Blender 2.49b.

Peter Shinners wrote:
> I've been discussing with several commercial vendors about how Python is 
> built into their applications. Currently we've been focused on how 
> Python is being compiled and which versions, compilers, UCS, and other 
> specifics are chosen. Being open source, Blender works a little 
> different. Hopefully any gurus can answer all or some of the questions 
> below.
> 
> 
> The Windows binaries do include Python. Is this a prebuilt version of 
> Python you deliver, or are you compiling your own? If you are compiling 
> your own, are you matching the compiler used by Python on Windows, or 
> does this match the compiler that builds the rest of Blender?

I'm not sure here, since I develop on Linux only. So I took a look at 
the svn repository:

This folder has .dll, .lib and .pdb files for Python from 2.2 to 2.6 and 
3.1 (from 2.3 to 3.1 there also also _d.dll files (debug versions):

/tags/lib2.4/windows/python/lib

There are also these subdirs there with versions compiled with different 
versions of VS:

lib25_vs2003/, lib25_vs2005/, lib25_vs2008 and lib26_vs2008/.

each has a set of .pdb, .lib, .dll and _d.dll files for the resp. Python 
version.

Here's a readme.txt:

/tags/lib2.4/windows/python/lib/readme.txt
"
* 2009-06-16: The Python 2.6 libraries are now 100% certain built with 
VC9.0 (VisualStudio 2008). I've added also a lib26_vs2008 directory with 
the same binaries, so if someone really needs py26 built with different 
vc version, it can be added in a similar way.


OLD LOG:
* 2008-10-14: The Python 2.5 libraries in this directory have been 
replaced with the version built with VC 9.0 (VisualStudio 2008).

* The files in this directory are built for VC 7.1 (MSVC 2003).  The 
2005 are in lib25_2005 (python version 2.5 built with VC 8.0).   Backup 
2003 files are in the directory lib25_2003.
"

Others can confirm if these versions work with Blender compiled with a 
different compiler, I don't know.

> On Unix platforms Blender gets compiled against a version of Python. At 
> startup, some attempt is made to find the Python libraries, although the 
> executable link is linked to the python .so. What is happening here when 
> Blender prints this at startup?
> """
> Compiled with Python version 2.6.2.
> Checking for installed Python... got it!
> """

It says Blender was compiled with Python version 2.6.2 and that we're 
checking if we can find a matching Python already installed in the 
user's system so we can access its default modules, like os, math, etc. 
For Blender up to 2.4x Blender required users to have Python installed 
under Linux. For Windows we used to ship a package with basic default 
modules so users didn't need to install Python themselves to run our 
bundled scripts.

> Blender looks like it will compile against a wide range of Python 
> versions, going back at least as far as Python 2.3 in the lastest 2.49b? 
> Is much effort required to support this, or does is the api flexible 
> enough to not worry?

Not much effort on the API side, but supporting older versions of Python 
limited what users could use in their scripts. We didn't officially 
support scripts using Python constructs newer than 2.2, for a time, then 
2.3.

The reason to support older Python versions was that some platforms took 
longer to update or didn't have newer versions available.

> Blender seems to include a large selection of Python plugins to run. I 
> am seeing them from the Scripts interface panel, but can't find any 
> correlating Python files anywhere. Where are these Python scripts 
> deployed and how are they registered in the interface like this?

Up to Blender 2.4x they were installed in a default dir (users could 
also install more in a user defined dir) close to other Blender data. So 
if you find where Blender installed its default files you'll find the 
scripts dir, too. Under Windows I guess the installer gives you the 
option of putting them together with Blender or in the default dir for 
config files.

Registration for menus goes like this: Blender on startup checks where 
the default dir for scripts is and parses all .py files there looking 
for an specific header pattern. It's all C code. It also scans the user 
defined dir, if the user defined one (User Preferences window, File 
Paths tab, in Blender).

The section "Registering scripts" here can give you more details about 
the header: 
http://www.blender.org/documentation/249PythonDoc/API_related-module.html

Note that it's all old, "deprecated" stuff, not valid in Blender 2.5. 
Talking about it...

Joe already wrote about Python in Blender 2.5. It's a much better 
implementation, Python is much more important for Blender there (large 
portions of the interface are defined via py scripts) and Campbell and 
others are being careful to make the API more Pythonic and bundled 
scripts follow PEP8.

So I suggest you take a better look at it, it's the present (still being 
worked on, like Joe said) and future of Blender.

-- 
Willian
http://encanners.net



More information about the Bf-python mailing list