How to deploy a common production environment?

Hi, I’m new to blender Python API, (but not new to Python and some other softwares API) and I’m trying to change scripts/startup location to deploy a common environment to multiple artists, ideally on a network location (yet mounted on a drive letter)
I’ve been looking for a way to do so, and stumble on BLENDER_USER_SCRIPTS env. var., but can’t manage to use it.

  • For what I understand, python scripts in this location should execute at startup (right?)
  • scripts put in the blender install dir. scripts/startup work as expected, print stuff and so on…
  • yet scripts put in BLENDER_USER_SCRIPTS path (even local path) are not evaluated

Is there something I got wrong ?
Is there an official method to have a common production environment without editing local files or settings on each workstation, (e.g. just by tweaking the system environment variables on blender startup) ?

(Blender 2.93, Windows)

Though I have never tried to change the default paths, I can give you some hints on this.

In order to get all of the loaded paths you can type this. When you call import from python this is where everything is searched from. If something is missing simply it would be impossible to import it.

>>> import sys
>>> sys.path
['\\blender\\3.0\\scripts\\startup', '\\blender\\3.0\\scripts\\modules',  ...

To get the map with all environment variables

>>> import os
>>> os.environ

To see if an environ variable is set.

>>> 'BLENDER_USER_SCRIPTS' in os.environ.keys()

I am not exactly sure about this. I think that blender.exe is hardcoded to include the scripts\startup from relative path. If you add the additional BLENDER_USER_SCRIPTS environ variable it will overload the sys.path thus the default will always prevail. The workaround is to remove the scripts\startup right from the beginning and inject your own (see inline python command line argument).

>>> path = [x for x in sys.path if x.endswith('scripts\\startup')][0]
>>> sys.path.insert(0, os.environ['BLENDER_USER_SCRIPTS'])

I think that it should be correct, unless I am wrong, someone correct me.

You can put “registered” scripts in the startup.blend file. You can even create different application templates, each with its own startup.blend and userpref.blend files.

1 Like

Hello !
Seems to be a good lead, there even is a --app-template <template> CLI option that I may use to direct Blender to a specific template at startup, I’ll keep you informed!
many thanks,

I also found my mistake with BLENDER_USER_SCRIPTS env. var. : for scripts to be evaluated on startup, they must reside in a startup folder inside BLENDER_USER_SCRIPTS location.

I finally just used startup scripts, which allow users to keep their app template and benefit from scripts, operators, menus initialized from startup scripts,
thanks again for your hints!

1 Like