如何为apache + wsgi网站设置LD_LIBRARY_PATH [英] How to set LD_LIBRARY_PATH for apache+wsgi website

查看:165
本文介绍了如何为apache + wsgi网站设置LD_LIBRARY_PATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的wsgi(apache +烧瓶)的网站上使用一个python库。



在独立的命令脚本中使用库时,我必须将库路径添加到LD_LIBRARY_PATH



所以这适用于独立脚本:

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

现在,当我尝试通过Apache + wsgi使用这个python库时,需要通过相同的路径到apache工人。如何实现?

解决方案

您是否需要编译和安装Python模块扩展库?如果是,则在编译和安装该Python模块时,将 LD_RUN_PATH 环境变量设置为库所在的目录。这样,位置嵌入在Python模块扩展本身中,您在运行时不需要 LD_LIBRARY_PATH



使用环境变量的唯一其他方法是在Apache的启动脚本中设置 LD_LIBRARY_PATH ,以便在Apache启动时,根据需要进行设置。这意味着使系统启动脚本变得虚弱,所以不是理想的或总是实用的。



最终的方法可能是有效的,但并不是一个很好的想法,甚至不会工作,是使用:

  LoadFile/usr/local/lib/libmylib.so

这将在启动时强制将特定库连接到Apache,但根据库的使用方式,这可能无法正常工作。


I'm trying to use a python library in my wsgi( apache + flask) based website.

While using the library in a standalone command script, I have to add the library path to LD_LIBRARY_PATH

So this works for standalone script:

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

Now when I try to use this python library through Apache+wsgi, I need to pass the same path to apache workers. How can I accomplish that?

解决方案

Is the library required by a Python module extension you have compiled and installed? If it was, set LD_RUN_PATH environment variable to the directory the library is in when compiling and installing that Python module. That way the location is embedded in the Python module extension itself and you don't need LD_LIBRARY_PATH at run time.

The only other way to do it using environment variables is to set LD_LIBRARY_PATH in the startup scripts for Apache so that when Apache is started it is set as you require. 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"

in the Apache configuration. This will force linking of the specific library into Apache at startup, but depending on how the library is being used, this may not work.

这篇关于如何为apache + wsgi网站设置LD_LIBRARY_PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆