Page MenuHome

PYTHONPATH ignored when using bundle python (tested in 2.63a Win32)
Closed, ResolvedPublic

Description

The environment variable PYTHONPATH is ignored when Blender finds the bundled python package on startup.
Problem: it prevents to use external module in custom directories.
This problem does NOT happen if the bundle python package is not present (delete 2.63/python directory for this). Of course, an external Python 3.2 install is required to get Blender working in this case; blender finds it and adds PYTHONPATH to the system path as it should.

How to reproduce: install Blender from windows installer, open a command windows, set PYTHONPATH to a value of choice, start blender, display Python console, execute following code: "import sys;print(sys.path)", verify that PYTHONPATH directory is not listed.

Event Timeline

This is for windows only, from the code seems this is why...

#ifdef _WIN32
/* cmake/MSVC debug build crashes without this, why only
* in this case is unknown.. */
{
BLI_setenv("PYTHONPATH", py_path_bundle);
}
#endif

So we can disable this but then if it crashes I'd need some windows developer to be able to look into this.

Could you check if this crashes still?, if not Im happy to remove.

I just tested a CMake/MSVC2008 debug build of the current SVN with the above line removed and I get no crash. As expected the PYTHONPATH appears in sys.path when using the bundled python.

Apparently it's related to setting the PYTHONPATH to an incompatible version?
http://lists.blender.org/pipermail/bf-blender-cvs/2010-September/031148.html

It would be good to test a release/debug builds together with PYTHONPATH set to a python 2.x or 3.0 installation, and see if that crashes. If not then I guess this can be removed.

Indeed, if PYTHONPATH points to the 'lib' directory of an incompatible python installation, then there is a crash on startup with the message "unable to load the file system codec". This problem also occurs when starting the Python32 interpreter in the same condition. The message is more explicit and shows what's happening:

E:\Python-3.2\PCbuild>set PYTHONPATH=E:\Python-2.6.2\Lib

E:\Python-3.2\PCbuild>python_d.exe
Fatal Python error: Py_Initialize: unable to load the file system codec
File "E:\Python-2.6.2\Lib\encodings\__init__.py", line 123
raise CodecRegistryError,\

So basically, the directory pointed by PYTHONPATH is searched first when importing the 'encoding' module as part of the interpreter initialization, and of course it crashes.
The problem does not occur if PYTHONPATH points to directories that do not contain an 'encoding' module, which I think is the most common case: the user has no reason to put a Python Lib directory in PYTHONPATH since the interpreter automatically adds it.

Since the problem also occurs with the interpreter, I don't think the workaround in Blender is justified. Can it be removed?

disabled and referenced this report, at least then there is some reference if someone runs into this again.

Campbell Barton (campbellbarton) changed the task status from Unknown Status to Resolved.May 19 2012, 12:11 PM

Hola :)
Thought I would add this report to this one, to keep from repetitive post.
This is reported from samiboy on graphicall
"I have been having a problem with running new builds after, say, 46384. That was the last build that didn't throw the following error:

---------------------------------------------------------------
found bundled python: c:\users\samschad\downloads\7150_win.x647.x64-46969\win7.x64-46969\2.3\python

Fatal Python error: Py_initialize: unable to load the file system codec
File "C:\Python26\Lib\encodings\_init_.py", line 123
raise CodecRegistryError,\

SyntaxError: invalid syntax
--------------------------------------------------------

I'm running win7x64 pro on a core i7 920 with 12 gigs of ram and dual GTX 470s.

any suggestions?"

I build trunk with MSVC2008 Pro + CMAKE on Win7.x64

Cheers,
~Tung

I have exactly the same problem. It's related to any build of Blender from Graphicall or blender.org's Builder. It doesn't happen in official 2.63.

I'm using Windows 7 64 bit. PYTHONPATH (computer Properties > Advanced) is set to Python 2.6, as I frequently use Blender 2.49.

Even though Blender finds bundled python - it doesn't matter if I point to it through --env-system-python argument or not - Blender still tries to use Python 2.6 from PYTHONPATH.
It causes an error on startup:
-----------------------------------------
found bundled python: C:\Users\Oskar\Desktop\blender-2.63-r50530-win64\2.63\python
Fatal Python error: Py_Initialize: unable to load the file system codec
File "C:\Python26\Lib\encodings\__init__.py", line 123
raise CodecRegistryError,\
^
SyntaxError: invalid syntax