How does this embedded Python packaging find its lib files?

44 Views Asked by At

Blender(*) for Windows is shipped with an embedded Python, like this:

blender-2.79b-windows64\
    2.79\
        python\
            bin\
                python.exe
                python35.dll    # only these 2 files
            lib\
                asyncio\
                collections\
                ... 
                + many .py and .pyd files

Launching python.exe works even if there is no system global Pyton install. Also, there is no .pth or ._pth file anywhere.

Question: how does python.exe know that the libs are in ..\lib?

Note (*): this is not specific to Blender (I used Blender just as an example), this is common for many software that ship Python embedded with them.

1

There are 1 best solutions below

3
mudskipper On

The 'lib' directory is the default directory here where Python finds all its stdlib modules. The directory name is basically a builtin default (which you could change by rebuilding with a different config). This is all extensively documented in https://docs.python.org/3/library/sys_path_init.html#sys-path-init and https://docs.python.org/3/library/site.html#module-site.

The question seems to assume that there is something special about the way the embedded Pythons finds modules, compared to a regular, non-embeddable Python. But there is not. Quote from the offical docs about the embedded Python on Windows:

As with the application use, packages can be installed to any location as there is an opportunity to specify search paths before initializing the interpreter. Otherwise, there is no fundamental differences between using the embedded distribution and a regular installation.

(https://docs.python.org/3/using/windows.html#embedding-python)