Distribute python libs with a PythonQt Project

Distribute python libs with a PythonQt Project

I use PythonQt to embed the Python scripting language into my C++ Qt application. When I tried to run my app on a different computer, that don’t have python installed, I got the following error:

Fatal Python error: Py_Initialize: unable to load the file system codec
Fatal Python error: ImportError: No module named ‘encodings’
Py_Initialize: unable to load the file system codec

Obviously Py_Initialize can not locate the python libraries. So if you want to distribute the python lib, you have to set the python home path before initializing. In order to achive this I did the following steps:

1. I created a new folder with the name “python” in my application folder

2. Then I copied only the Lib folder (from python34)  into my new folder. Like this “myapp/python/lib”

3. Set the python home path to my python folder before Py_Initialize

QString pythonPath = QCoreApplication::applicationDirPath()+"/python/";
Py_SetPythonHome((wchar_t*)pythonPath.data());

// init PythonQt and Python itself
PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);