virtualenv可以找到重定位的库文件

virtualenv可以找到重定位的库文件

本文介绍了virtualenv可以找到重定位的库文件(例如MySQLdb的mysqlclient库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够共享一个自包含的virtualenv,即确保安装的所有脚本都可以直接运行而无需进行任何设置.例如.我在使用MySQL-python的virtualenv中安装了一个脚本.不幸的是,导入MySQLdb会寻找一个共享库(libmysqlclient.so),该库已移到系统上标准目录之外的其他位置.有没有一种方法可以保证我的virtualenv每次有人使用它时都能找到该库?

I would like to be able to share a virtualenv that is self contained, i.e. insure that all scripts installed are able to run directly without needing to set anything.E.g. I install a script in my virtualenv that uses MySQL-python. Unfortunately importing MySQLdb looks for a shared library (libmysqlclient.so) that was moved elsewhere than the standard directories on my system.Is there a way to guarantee that my virtualenv will find the library every time someone uses it?

推荐答案

我知道这个问题有点老了,但是我很想分享我的解决方案,因为它无法通过Google找到它:

I know this question is a bit old, but I'd love to share my solution for the lack of finding it via Google:

deactivate ()函数中,添加以下行:

In the deactivate () function, add the following lines:

    if ! [ -z ${_OLD_LD_LIBRARY_PATH+x} ] ; then
        LD_LIBRARY_PATH="$_OLD_LD_LIBRARY_PATH"
        export LD_LIBRARY_PATH
        unset _OLD_LD_LIBRARY_PATH
    fi

请注意,我使用的是否定的-z表达式-PATHPYTHONHOME的现有重置脚本使用-n,如果_OLD_LD_LIBRARY_PATH设置为空字符串,则错误地将其评估为false.

Note that I'm using a negated -z expression - the existing reset scripts for PATH and PYTHONHOME use -n, which incorrectly evaluates to false if _OLD_LD_LIBRARY_PATH is set to an empty string.

然后,在deactivate ()函数下方,添加以下部分:

Then, below the deactivate () function, add the following section:

_OLD_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
LD_LIBRARY_PATH="$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH

这篇关于virtualenv可以找到重定位的库文件(例如MySQLdb的mysqlclient库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:31