Saturday, July 3, 2021

Python 3.9 run Windows Server 2008 problem

According to https://www.python.org/downloads/windows/:
Python 3.9 cannot be used on Windows 7 or earlier.
But we had a server with Windows Server 2008 R2 installed 🤷 and while running a project with Python 3.9 on Windows Server 2008 R2, we encountered the following issue: 
python.exe run.py exited with -1073740777. It is Unknown Software Exception: 0xc0000417.
Failed process printed the next output:

D:\Jenkins\workspace\TEST>"D:\Jenkins\workspace\TEST\project\python.exe" run.py Python path configuration: PYTHONHOME = (not set) PYTHONPATH = (not set) program name = 'D:\Jenkins\workspace\TEST\project\python.exe' isolated = 0 environment = 1 user site = 1 import site = 1 sys._base_executable = '\xc5V\u3241Z' sys.base_prefix = '.' sys.base_exec_prefix = '.' sys.platlibdir = 'lib' sys.executable = '\xc5V\u3241Z' sys.prefix = '.' sys.exec_prefix = '.' sys.path = [ 'D:\\Jenkins\\workspace\\TEST\\project\\python39.zip', '.\\DLLs', '.\\lib', '', ]

The variables sys._base_executable and sys.executable are corrupted and filled with arbitrary data.

We had sitecustomize.py file, with sys.executable variable update to required python.exe, but the problems still reproduced.

The only solution helped:

It is required to set the next environment variables (in our case we set them in Jenkins):

set PYTHONPATH=%PYTHONPATH%;%WORKSPACE%\project

set PYTHONHOME=%PYTHONHOME%;%WORKSPACE%\project

set __PYVENV_LAUNCHER__=%WORKSPACE%\project\python.exe