# PYTHONPATH ignored?

Blender 2.82a on Windows 10 - I'm trying to set th PYTHONPATH environment variable before launching Blender, but it seems that Blender's version of Python somehow has disabled the standard Python behaviour of putting paths from PYTHONPATH in sys.path at startup? If I launch with this batch file:

set BLENDER_USER_SCRIPTS=\\ourshare\ourscripts
set PYTHONPATH=\\ourshare\ourpackages
"C:\Program Files\Blender Foundation\Blender 2.82\blender.exe"


I'd expect sys.path to contain an entry of "\\ourshare\ourpackages" and be able to import things from there, but it doesn't. os.environ['PYTHONPATH'] does have the value "\\ourshare\ourpackages", so Blender doesn't seem to be deleting it from the environment it passes to its Python when it starts that up, which is why I'm wondering if they've customized their interpreter to not do the standard behaviour.

I can use a startup script in \\ourshare\ourscripts\startup to do the additions to sys.path, but if I want those available to all the startup scripts, the order of executing those is indeterminate (or at least not documented)? It may be whatever the filesystem returns when Blender queries it? It would be cleaner if we could use PYTHONPATH as we do with all our other Python-including DCC apps.

• If you have the same x.y version of python installed that blender uses, can rename the blender python path and blender will pick up your system or venv version. – batFINGER Mar 30 '20 at 4:40
• Digging through the Blender C source code, it looks like they are initializing their Python interpreter with a global configuration variable Py_IgnoreEnvironmentFlag set to a value that by default is false. This causes Python to ignore PYTHONPATH, PYTHONHOME, etc. There is a Blender command line variable --python-use-system-env which can be set to override this. It isn't mentioned on the current documentation page, but it shows up if you run blender --help. I think this will solve my problems. I'll see if I can find a place to report to documentation lapse. – YKdvd Mar 30 '20 at 5:36
• It is in the advanced CLI help section somewhere. The 2.80 doco is more up to date in some ways than others. – batFINGER Mar 30 '20 at 5:43
• Looks like it was added in 2.82, but the current online docs purportedly listing all the 2.82 command line options don't reflect it (it isn't in the 2.83 dev page either). There is a mention on a "Tips and Tricks" page. wiki.blender.org/wiki/Reference/Release_Notes/2.82/Python_API docs.blender.org/manual/en/latest/advanced/command_line/… docs.blender.org/api/current/info_tips_and_tricks.html – YKdvd Mar 30 '20 at 6:02
• I'll contact Aaron to get this included in the CLI page. The commit that introduced this change was developer.blender.org/… – Robert Gützkow Mar 30 '20 at 10:38

The PYTHONPATH environment variable is ignored since commit rBS7c2f0074f3fe2411daa7a6e351d7cbc535246871. It caused trouble in the past, because users have set the PYTHONPATH during the installation without being aware of that Blender would attempt to use the modules of this Python interpreter. If the Python version wasn't compatible, Blender wouldn't work.
The CLI argument --python-use-system-env is now documented.
• Is there some other limitation instead when it comes to the python executable? No matter what I try with BLENDER_SYSTEM_PYTHON or PYTHONHOME, you can still notice how the built-in one was started earlier. – mirh May 4 '20 at 17:16
• Set the two aforementioned variables to whatever python altinstall you may have on your system (and even override PYTHONPATH just for peace of mind). Rather than seeing my alternative executable being run (as can be noticed by the "build date", or the "installation-dependent default" entries in sys.path), it seems like the most I can get is PYTHONHOME to be appended to the standard python binary. But no way to actually start another one (which afaik is what BLENDER_SYSTEM_PYTHON should do?). – mirh May 6 '20 at 14:44
• @mirh The same applies to Linux, the Python interpreter is part of Blender's binary and can't be replaced (unless of course you compile Blender yourself). PYTHONPATH is for setting the search path for modules files, PYTHONHOME is for the search path for Python libraries and BLENDER_SYSTEM_PYTHON is for the Python libraries as well (just specifically for Blender). May I ask why you're trying to replace the interpreter? – Robert Gützkow May 18 '20 at 12:05