简体   繁体   English

"如何为 apache+wsgi 网站设置 LD_LIBRARY_PATH"

[英]How to set LD_LIBRARY_PATH for apache+wsgi website

I'm trying to use a python library in my wsgi( apache + flask) based website.我正在尝试在基于 wsgi( apache + flask) 的网站中使用 python 库。

While using the library in a standalone command script, I have to add the library path to LD_LIBRARY_PATH在独立命令脚本中使用库时,我必须将库路径添加到 LD_LIBRARY_PATH

So this works for standalone script:所以这适用于独立脚本:

# export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64
# python script.py

Is the library required by a Python module extension you have compiled and installed?您编译和安装的 Python 模块扩展是否需要该库? If it was, set LD_RUN_PATH<\/code> environment variable to the directory the library is in when compiling and installing that Python module.如果是,请将LD_RUN_PATH<\/code>环境变量设置为编译和安装该 Python 模块时库所在的目录。 That way the location is embedded in the Python module extension itself and you don't need LD_LIBRARY_PATH<\/code> at run time.这样,该位置就嵌入在 Python 模块扩展本身中,并且您在运行时不需要LD_LIBRARY_PATH<\/code> 。

The only other way to do it using environment variables is to set LD_LIBRARY_PATH<\/code> in the startup scripts for Apache so that when Apache is started it is set as you require.使用环境变量的唯一其他方法是在 Apache 的启动脚本中设置LD_LIBRARY_PATH<\/code> ,以便在启动 Apache 时根据需要进行设置。 This means fiddling with system startup scripts so is not ideal or always practical.这意味着摆弄系统启动脚本,因此并不理想或总是不实用。

One final way which may work but isn't really that great of an idea and may not even work, is to use:最后一种可能有效但不是一个好主意甚至可能无效的最后一种方法是使用:

LoadFile "/usr/local/lib/libmylib.so"

For me, the simpler solution was to walk through the LD_LIBRARY_PATH and create softlinks to \/usr\/lib.对我来说,更简单的解决方案是遍历 LD_LIBRARY_PATH 并创建指向 \/usr\/lib 的软链接。 Very efficient if your LD_LIBRARY_PATH is not too long:如果您的 LD_LIBRARY_PATH 不太长,则非常有效:

~/opt/lib$ for f in $(ls) ; do sudo ln -s `pwd`/$f /usr/lib/$f ; done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM