I have a development server for my Django application running Cent OS 6. I'm serving the application using Apache and mod_wsgi. I read a lot about the default Python that comes with Cent and so I installed an alternate Python 2.7.6 from source and compiled it with --enable-shared. I also installed mod_wsgi from source and pointed it to the new Python installation.
However, every time I try to run the app, I keep getting the following error from lxml:
..lib/python2.7/site-packages/lxml/objectify.so: undefined symbol: PyUnicodeUCS2_Format
Another notable thing in the error is that the Python executable being used is not the desired one:
Python Executable: /usr/bin/python
instead of /home/jenkins/local/bin/python
I've been looking for this for hours to no avail.
How can I solve this?? Thanks in advance.
You are trying to use a version of lxml compiled against one installation of Python against a different Python installation. The two Python installations are not the same. Specifically the one lxml was compiled against had 16 bit Unicode character width specified when Python itself was compiled. The Python run time being used though was compiled for 32 but Unicode character width. It will therefore fail.
The things you need to check are, what shared Python library is mod_wsgi actually using at run time and is it the correct one. For how to do this see:
If it is picking up the wrong library, the mod_wsgi needs to be recompiled against the correct Python installation but where
LD_RUN_PATH
environment variable is set as explained in the document.The next thing you need to check is that you are not telling mod_wsgi to use a Python virtual environment that was constructed against a different Python installation than what mod_wsgi is using.
One last thing you can do is ensure you build your custom Python installation with 32 bit Unicode characters. When you build Python from source code, it defaults to 16 bit. On Linux, distros own Python installations are always compiled for 32 bit Unicode, which is why you have got in this problem when you have started mixing Python installations.
In apache, stablish the path to the python executable using the directive
WSGIPythonHome
: