0
$\begingroup$

I have experimented quite a bit with extending the modules that come with the blender bundled python. It is confusing to me, and seems not well documented anywhere how it actually works.

A folder called Python exists in the Blender folder, and it is described in numerous places as the bundled python. In it, you can find a structure very similar to that of a Python venv. That is, you can create a virtual python environment by using the venv command as:

python3.7m -m venv myVenvFolderPath --copies

This follows regular python convention. Since the python folder contains some other dependencies you need to copy them as well, in order to recreate a venv that is as similar to that of the bundled python that comes with Blender (see this explanation for details)

Furthermore, this binary (python3.7m in the blender python folder) is referred to online virtually everywhere as the bundled python interpreter.

however, i doubt that it really is. If you delete this binary, Blender will still run very happily. In the python console inside of blender, you can then run:

import sys
sys.executable

and you will find that Blender will have just found some other python 3.7 binary, whatever it can find in the path of your system. Blender runs perfectly fine with this, even if the python binary that it found was actually another version. On my system, Blender finds the "Python3.7m" version that is in the path, that is actually version 3.7.10, and not 3.7.7 version of Python. Again, that is all fine with Blender. I also have built Python from source, and have fed the python binary (as a venv) to blender, using a wide variety of build options. Inside of blender, there is never any problems that I have encountered, and mysteriously Blender always reports version 3.7.7 in the startup of the python console inside of blender.

Right now, I am inclined to guess that the python binary that comes with Blender is actually not the interpreter at all, but that the interpreter is either statically linked into blender, or available as a dynamic library. If someone could verify that, it would really illuminate me, thanks.

Second part of this question, which I think is connected to the first part, is why I am getting very odd errors and crashes of Blender, when i add certain modules to my python environment. This happens regardless of what version of python I am using to create the venv, or even doing the pip install.

This happens when i try to run matplotlib with any backend that is interactive, except for the "webagg" option. Since the built-in python interpreter (which is located somewhere mysteriously) does not have tkinter built in, I have tried using QT4 and cairo as visual backend frameworks. Using any of them will properly bring up the matplotlib.pyplot figures I want in interactive mode, but afterwards Blender becomes unstable and will always crash on me after some time. The error is always the same, a full immediate crash due to segm fault, and the output in the terminal reading:

ERROR (gpu.shader): GPU_material_compile FragShader: 
      | 
10412 | const vec3 cons26 = vec3(0,000000000000, 0,000000000000, 0,000000000000);
      | 
      | Error:  C1068: too much data in type constructor
      | 
10414 | const float cons28 = float(0,000000000000);
      | 
      | Error:  C1068: too much data in type constructor
      | 
10415 | const float cons29 = float(1,000000000000);
      | 
      | Error:  C1068: too much data in type constructor
      | 
10416 | const float cons30 = float(1,000000000000);
      | 
      | Error:  C1068: too much data in type constructor
      | 
10418 | const vec3 cons35 = vec3(0,000000000000, 0,000000000000, 0,000000000000);
      | 
      | Error:  C1068: too much data in type constructor

All interactive backends that "work" yields this instability, with the exception of "webagg", which requires the tornado webserver to be installed with pip. This one works great, using the web-browser for the plots, except that I need to go to the terminal to issue a ctrl-c, in order not to freeze up Blender.

System Info

I am working in Ubuntu 18.04, with Blender 2.91.2. I am on a laptop, Lenovo thinkpad P1, gen 2, with a Quadro T1000 graphics card

$\endgroup$
6
  • $\begingroup$ You put way too much detail before asking the question! For an explanation, I just learned today from somewhere else on the Stack Exchange that if you delete blender’s native Python (it is indeed python, make no mistake) blender will make up for it for you, and try to find python somewhere else on your system. It’s not because it’s secretly a scam python or something. Blender improvises. $\endgroup$
    – TheLabCat
    Feb 25, 2021 at 3:29
  • $\begingroup$ Check out the comments on this question blender.stackexchange.com/q/212945/73575 They might help you :-) $\endgroup$
    – TheLabCat
    Feb 25, 2021 at 3:31
  • $\begingroup$ @ZargulTheWizard, if you delete the python directory, then Blender is supposed to look for another interpreter, yes. I did not delete the python folder, but the python binary from within the folder in the example above. Nonetheless, no matter what I have tried,it seems that the binary is actually not changed... that is, the python interpreter seems to not be changed, although the folder that contains all the modules will be the only thing changed. That is how it seems from the observations I made $\endgroup$ Feb 25, 2021 at 6:57
  • $\begingroup$ Why are there commas and not dots in the floats in error message? Should the be float2? $\endgroup$
    – Emil
    Feb 25, 2021 at 7:55
  • $\begingroup$ @Emil, that is truly weird indeed. If that was C or GLSL code, it would be a likely bug by a coder from a culture using comma as a decimal seperator. $\endgroup$ Feb 25, 2021 at 10:22

0

You must log in to answer this question.

Browse other questions tagged .