I built a project to a python lib and after that I want to migrate and run the lib to server or any other machine. but I meet a dependency problem:
The .so file cysteps_dist.so
in the lib step
folder has some dependend .so libraries located in the temporary build
folder. If I just copy the lib step
folder to other machine, it won't work.
So, I want to copy these dependend libraries (example libomega_h.so
and libsundials_cvode.so.3
and any potentially missing library file) to the same step
folder.
I want to change the env variable LD_LIBRARY_PATH
when I use import steps
so that the copied libraries can be found.
But I don't want to use command export LD_LIBRARY_PATH=/usr/lib/python3/dist-packages/steps
every time before command import steps
. So I am looking for a way to change the __init__.py
file or any other source file in the step
folder to achieve this "specify env variable" effect.
I tried some code like followed but failed:
import os
if not 'LD_LIBRARY_PATH' in os.environ:
os.environ["LD_LIBRARY_PATH"] = os.path.dirname(__file__)
else:
os.environ["LD_LIBRARY_PATH"] = os.path.dirname(__file__) + ":" + os.environ["LD_LIBRARY_PATH"]
os.execve(os.path.realpath(__file__), (' ',), os.environ)
so, how to make the .so file find its dependencies in its file location?