Include Python executable with Blender. #43486

Closed
opened 2015-01-30 11:44:37 +01:00 by Campbell Barton · 33 comments

This tasks proposed to include python in Blender (python.exe on windows, so every Blender installation can be ensured to run the same version of Python that's included with Blender).

Motivation

Short Version: subprocesses.

Blender currently uses Python for many tasks, but anything that takes longer then a few seconds will lock Blender up, Currently some addons load a separate Blender process (SketchFab for example), However if this is only to transfer data, the overhead of running an entire Blender instance, just for its Python interpreter isn't very efficient.

Uses for Python subprocesses:

  • General online integration (file upload/download ... asset manager, cloud... etc).
  • Background processing (avoid locking up Blender).

Blender could just run Python, but this means you have to install Python and have it available in the systems PATH which isn't so common on Windows.

Including the python binary means we can ensure that there will be a python3.4 for certain.

Size considerations

On my system (64bit Linux) (python+libpython3.4) compress to ~1mb. It will vary between platforms but should stay under 2-3mb.

Platform maintainers

Since we already include a full python for each platform. Including the python binary in fact isn't much extra work (will be included in svn lib/(platform)/, will have to be copied across from the system).
Note that this will have to be a static build (since we aren't LD_PRELOADing libpython)

Access from Blender

Currently blender includes: 2.73/python/lib/python3.4

The python binary can be located at: 2.73/python/bin/python

We can have an attribute to access this to avoid each script having to find the path.
eg bpy.app.python_path. (as we have for bpy.app.binary_path to access Blender's binary)

For Linux distributions which don't bundle Python, this can simply point to $(which python)

This tasks proposed to include `python` in Blender (`python.exe` on windows, so every Blender installation can be ensured to run the same version of Python that's included with Blender). Motivation ---- *Short Version:* subprocesses. Blender currently uses Python for many tasks, but anything that takes longer then a few seconds will lock Blender up, Currently some addons load a separate Blender process (SketchFab for example), However if this is only to transfer data, the overhead of running an entire Blender instance, just for its Python interpreter isn't very efficient. Uses for Python subprocesses: - General online integration (file upload/download ... asset manager, cloud... etc). - Background processing (avoid locking up Blender). Blender could just run Python, but this means you have to install Python and have it available in the systems `PATH` which isn't so common on Windows. Including the `python` binary means we can ensure that there will be a `python3.4` for certain. Size considerations ---- On my system (64bit Linux) (`python`+`libpython3.4`) compress to ~1mb. It will vary between platforms but should stay under 2-3mb. Platform maintainers ---- Since we already include a full python for each platform. Including the python binary in fact isn't much extra work (will be included in svn `lib/(platform)/`, will have to be copied across from the system). Note that this will have to be a static build (since we aren't `LD_PRELOAD`ing `libpython`) Access from Blender ---- Currently blender includes: `2.73/python/lib/python3.4` The python binary can be located at: `2.73/python/bin/python` We can have an attribute to access this to avoid each script having to find the path. eg `bpy.app.python_path`. (as we have for `bpy.app.binary_path` to access Blender's binary) For Linux distributions which don't bundle Python, this can simply point to `$(which python)`
Author
Owner

Changed status to: 'Open'

Changed status to: 'Open'
Author
Owner

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Added subscriber: @mont29

Added subscriber: @mont29

Wouldn't mind that, but I’m not a maintainer so… ;)

Anyway, my main question is: is it really worth it? Do we have use cases where it would really benefit to use lighter py process instead of full blender?

Here, empty py process is about 3MB, and empty blender process (in background) is about 37MB. This is much much bigger, but is it really an issue still? I would not expect more than a few of those processes running at once (usually no more than one actually), and since blender is already in mem, loading it again is really fast too. So unless you intend to start hundreds of processes in a very short time…

Wouldn't mind that, but I’m not a maintainer so… ;) Anyway, my main question is: is it really worth it? Do we have use cases where it would really benefit to use lighter py process instead of full blender? Here, empty py process is about 3MB, and empty blender process (in background) is about 37MB. This is much much bigger, but is it really an issue still? I would not expect more than a few of those processes running at once (usually no more than one actually), and since blender is already in mem, loading it again is really fast too. So unless you intend to start hundreds of processes in a very short time…

Added subscriber: @dfelinto

Added subscriber: @dfelinto

+1
As a user I can see the benefit of this as well. Do you think the Blenderplayer should have this too? Or should it be optional?

+1 As a user I can see the benefit of this as well. Do you think the Blenderplayer should have this too? Or should it be optional?
Author
Owner

@mont29, yep, we can keep using blender just for py access, its not horrible but not really nice either, Since we are considering having asset managers that can download data in the background, I would rather this not be depending on an entire blender process.

@dfelinto, blenderplayer using same python as Blender, so some way for it to find the Python binary is trivial.

@mont29, yep, we can keep using blender just for py access, its not horrible but not really nice either, Since we are considering having asset managers that can download data in the background, I would rather this not be depending on an entire blender process. @dfelinto, blenderplayer using same python as Blender, so some way for it to find the Python binary is trivial.

Added subscriber: @Januz

Added subscriber: @Januz

+10000
I've recently implemented some code that works in the background for an addon, and had to use the Blender binary just for Python. A simple py script would be lighter, faster and it'd allow me to decouple it completely from Blender so users can call it from the cli (or other scripts).

You mention it has to be a static build. Is bpy.app.python_path always going to point to a python bin, or do we have to try it (and have a fallback)?

+10000 I've recently implemented some code that works in the background for an addon, and had to use the Blender binary just for Python. A simple py script would be lighter, faster and it'd allow me to decouple it completely from Blender so users can call it from the cli (or other scripts). You mention it has to be a static build. Is `bpy.app.python_path` always going to point to a python bin, or do we have to `try` it (and have a fallback)?

Added subscriber: @Lapineige

Added subscriber: @Lapineige
Author
Owner

@Januz bpy.app.python_path Would always point to a valid python binary, weather on portable blender.org setup's or on linux distro's which include python.
Of course we cant help if someone manually deletes python from blender, but this isn't some case that needs to be supported - if someone manually removes files in Blender, it can be considered a broken installation.

A Python script writer should be able to call python in a single line of code, without searching for it.

@Januz `bpy.app.python_path` Would always point to a valid `python` binary, weather on portable blender.org setup's or on linux distro's which include python. Of course we cant help if someone manually deletes python from blender, but this isn't some case that needs to be supported - *if someone manually removes files in Blender, it can be considered a broken installation.* A Python script writer should be able to call python in a single line of code, without searching for it.

Added subscriber: @SynaGl0w

Added subscriber: @SynaGl0w
Member

Added subscriber: @jta

Added subscriber: @jta
Member

Added subscriber: @GregZaal

Added subscriber: @GregZaal
Member

Added subscriber: @tetha.z

Added subscriber: @tetha.z

Added subscriber: @Brachi

Added subscriber: @Brachi
Member

Added subscriber: @brita

Added subscriber: @brita
Member

@ideasman42 you want to have linux pointing to the system installed python? why? this could lead to mismatching python versions.

@ideasman42 you want to have linux pointing to the system installed python? why? this could lead to mismatching python versions.
Author
Owner

@brita re: system python.

I'm referring to packaged versions of Blender (as you would install on debian/redhad/fedora.... etc), these dont bundle Python.
We can assume python3.4 is in the PATH in these cases (We can use include defines to construct the path dynamically so Py3.5+ works too, whichever version of Python Blender is compiled against).

@brita re: system python. I'm referring to packaged versions of Blender (as you would install on debian/redhad/fedora.... etc), these dont bundle Python. We can assume `python3.4` is in the PATH in these cases (We can use include defines to construct the path dynamically so Py3.5+ works too, whichever version of Python Blender is compiled against).

Added subscriber: @marcino15

Added subscriber: @marcino15

It will support pip?

It will support pip?
Author
Owner

@marcino15

Initially no, it wouldnt support pip, at the moment we remove distutils from the bundled Python installation.

Including it isn't especially difficult, it was just removed because there was no reason to have it and to save a bit of space.

Im not against this, but if we include distutils it may open us up to some maintenance issues. (users upgrading Blender and wanting to keep existing pip modules for eg).
So I would first like to evaluate the use-case for having pip with Blender to see if its really worth bothering with.

@marcino15 Initially no, it wouldnt support pip, at the moment we remove `distutils` from the bundled Python installation. Including it isn't especially difficult, it was just removed because there was no reason to have it and to save a bit of space. Im not against this, but if we include `distutils` it may open us up to some maintenance issues. (users upgrading Blender and wanting to keep existing pip modules for eg). So I would first like to evaluate the use-case for having pip with Blender to see if its really worth bothering with.
Member

Added subscriber: @jensverwiebe

Added subscriber: @jensverwiebe
Member

Thats easy doing and i see it's benefits.
I will provide a bin to our libs and adapt scons to place it in VERSION/python/bin

So we can test this and decide pro/contra much better in the end.

Jens

Thats easy doing and i see it's benefits. I will provide a bin to our libs and adapt scons to place it in VERSION/python/bin So we can test this and decide pro/contra much better in the end. Jens

Is there any patch to test this? I believe this would fix issues like this: #43869

Is there any patch to test this? I believe this would fix issues like this: #43869

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Added subscriber: @Sergey

Added subscriber: @Sergey
Author
Owner

@dfelinto, I dont think this makes any difference for #43869

@dfelinto, I dont think this makes any difference for #43869
Author
Owner

Update. added bc2f77e1da

Now we only have to copy the executable over on install, and include in lib/

Update. added bc2f77e1da Now we only have to copy the executable over on install, and include in `lib/`

@ideasman42 but if we are distributing the Python binary with Blender we can(/should?) also link Blender against it (which would take care of the forementioned issue).

That is basically what we do in OSX with -DWITH_PYTHON_FRAMEWORK.

@ideasman42 but if we are distributing the Python binary with Blender we can(/should?) also link Blender against it (which would take care of the forementioned issue). That is basically what we do in OSX with **-DWITH_PYTHON_FRAMEWORK**.
Member

@ Dalai: the python binary i added to darwin libs is fully static against python and has nothing todo with python_framework.
Place it in the bundle in an apropiate way ( ....2.47/python/bin ) and you are done.
Now you must just call it instead of new blender py instances for subprocesses ....

Jens

@ Dalai: the python binary i added to darwin libs is fully static against python and has nothing todo with python_framework. Place it in the bundle in an apropiate way ( ....2.47/python/bin ) and you are done. Now you must just call it instead of new blender py instances for subprocesses .... Jens
Author
Owner

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Campbell Barton self-assigned this 2015-06-03 12:17:00 +02:00
Author
Owner

Added for linux/osx/windows closing.

Added for linux/osx/windows closing.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
15 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#43486
No description provided.