Why should you build UPBGE for Python3.10.6?
One example is if you want to integrate UPBGE with ROS2.
And there may be many other reasons.
Install Packages
Install essential packages with the package manager.
sudo apt update sudo apt install build-essential git subversion cmake libx11-dev libxxf86vm-dev libxcursor-dev libxi-dev libxrandr-dev libxinerama-dev libegl-dev sudo apt install libwayland-dev wayland-protocols libxkbcommon-dev libdbus-1-dev linux-libc-dev
Download upbge 0.3 Sources
Create a directory for the source code like e.g.:
mkdir ~/upbge cd ~/upbge
Unzip the source code inside the upbge-folder, so the resulting structure is like this:
~/upbge/blender
Download Libraries (from blender v3.0)
Using precompiled libraries is quickest way to get a feature complete UPBGE 0.3 build and can be downloaded as follows:
mkdir ~/upbge/lib cd ~/blender-git/lib
svn checkout https://svn.blender.org/svnroot/bf-blender/tags/blender-3.0-release/lib/linux_centos7_x86_6
Edit source code in two files
In file ~/upbge/blender/source/gameengine/Expressions/intern/PyObjectPlus.cpp, do a simple search and replace. Search for string “_PyUnicode_AsStringAndSize” and replace it with “PyUnicode_AsUTF8AndSize”
In file ~/upbge/blender/source/gameengine/Ketsji/KX_PythonInit.cpp search for string “_Py_fopen” and replace it with “_Py_wfopen”.
In the same file replace the entire function “createPythonConsole” with:
void createPythonConsole()
{
// Use an external file, by this way the user can modify it.
char filepath[FILE_MAX];
BLI_strncpy(filepath, BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, “bge”), sizeof(filepath));
BLI_path_append(filepath, sizeof(filepath), “interpreter.py”);
const char* sz = filepath;
std::vector<wchar_t> vec;
size_t len = strlen(sz);
vec.resize(len+1);
mbstowcs(&vec[0],sz,len);
const wchar_t* wsz = &vec[0];
//const wchar_t kaj = “r+”;
const wchar_t *kaj = L"r+";
// Use _Py_fopen to make sure we use the same fopen function as python use.
FILE *fp = _Py_wfopen(wsz, kaj);
// Execute the file in python.
PyRun_SimpleFile(fp, filepath);
}
Languages
Languages are not included in upbge zip file, so you have to download it from blender on github:
github dot com/blender/blender
(You can use latest version, it will work also).
Download the folder “locale” so you get the following structure in your source files:
~/upbge/blender/release/datafiles/locale
Build the source code
cd ~/upbge/blender
BUILD_CMAKE_ARGS=“-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.10.so -DPYTHON_INCLUDE_DIR=/usr/include/python3.10 -DTEST_PYTHON_EXE=/usr/bin/python3.10” make
If you have python installed somewhere else you need to make changes to the command above.
BE AWARE that the final install in the build process will fail, but there is a quick fix to this.
Tell UPBGE to use python of the Ubuntu distribution
Now, edit the generated file ~/upbge/build_linux/source/creator/cmake_install.cmake
In here, delete all sections that caused the above make to fail.
To avoid overwriting the file you just edited with another auto-generated, do the following:
cd ~/upbge/build_linux
make install
FINALLY, delete the Python-folder inside:
~/upbge/build_linux/bin/3.0
Now you should be able to run UPBGE:
cd ~/upbge/build_linux/bin/
change permissions of the bash script “blender”, to allow executing as a program, and run:
./blender
BE AWARE that there will be a few add-ons not loading during start-up. You get these for blender v3.0 on github:
github dot com/blender/blender-addons.
Done.