I deploy my Django web sites on Apache2 with mod_wsgi on ubuntu.
In my Django views, I import a module that requires a specific path set in LD_LIBRARY_PATH.
When I set LD_LIBRARY_PATH in /etc/apache2/envvars as:
export LD_LIBRARY_PATH=/home/user/target_libdir:$LD_LIBRARY_PATH
it works.
However, on my server I run multiple django web sites, each in independent VirtualHost entry, with independent wsgi scripts.
The problem is that the web sites need to use different LD_LIBRARY_PATH versions.
So, how can I set LD_LIBRARY_PATH individually for every django web site?
You can't do it. The LD_LIBRARY_PATH is only read once on initial process start. It cannot be set once process is running nor can you set it again prior to a fork. You can set it prior to an exec, but mod_wsgi daemon processes are fork only and not an exec.
Well there are situations where you simply can't set the LD_LIBRARY_PATH variable before the script is run and you still would like to import one or two of custom libraries - lets say from a home directory on your hosting server where you have very little access rights, or customize it for every site like in the question above.
In these cases where all sensible solutions are not available you can load the libraries using ctypes and than import the module that uses them. It is simple to adopt this idea to load all libraries from a custom folder for every site, like in the question above.
So for the issue I had with libpuzzle with one dependency I ended up doing:
from ctypes import *
lib1 = cdll.LoadLibrary('/home/username/lib/libpuzzle.so')
lib2 = cdll.LoadLibrary('/home/username/lib/libgd.so')
import pypuzzle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With