简体   繁体   English

如何使用python脚本在Mac上导出DYLD_LIBRARY_PATH

[英]How to export DYLD_LIBRARY_PATH on mac using python script

I am using ctypes to load my library. 我正在使用ctypes加载我的库。 Code is something like 代码就像

currPath = os.getcwd() 
libPath = os.path.join(currPath, platform) 
print libPath 
if(platform == 'win32'): 
    os.environ['PATH'] = os.environ['PATH'] + r';' + libPath 
if(platform == 'darwin'): 
    os.environ['DYLD_LIBRARY_PATH'] = libPath {/Users/labuser/Desktop/lib} 
print os.environ['DYLD_LIBRARY_PATH']

But when I try to load my library, it doesn't find the library path. 但是,当我尝试加载库时,找不到库路径。

What are the probable solution. 有什么可能的解决方案。 When on terminal before launching the python script I do export DYLD_LIBRARY_PATH = PATH, then my python script works fine. 在启动python脚本之前在终端上时,我确实导出DYLD_LIBRARY_PATH = PATH,所以我的python脚本工作正常。

If you are trying to set DYLD_LIBRARY_PATH in the same script that loads your library code, I think this will not work. 如果您试图在加载库代码的同一脚本中设置DYLD_LIBRARY_PATH ,我认为这将无法正常工作。 The environment variable needs to be set before python starts up, from the shell. 需要从外壳程序在python启动之前设置环境变量。 Setting it in os.environ is not persistant beyond the current python environment anyways. 无论如何,在os.environ中设置它并不持久。

What @summea refers to in his comment link is the need to create some type of shell script, or adding this to your shell environment via ~/.profile or whatever is the equivalent location for your operating system and shell. @summea在他的注释链接中所指的是需要创建某种类型的Shell脚本,或者通过〜/ .profile或操作系统和Shell的等效位置将其添加到Shell环境中。

The reason that it works, when you export the variable and then start your script is that the variable is set when python starts. 导出变量然后启动脚本时,它起作用的原因是在python启动时设置了变量。 Equally you could probably launch your script with something like DYLD_LIBRARY_PATH="path" ./script.py and it would also work with the temporary variable setting. 同样,您可能可以使用诸如DYLD_LIBRARY_PATH="path" ./script.py类的脚本来启动脚本,它也可以与临时变量设置一起使用。

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

相关问题 如何使用buildbot指定DYLD_LIBRARY_PATH? - how to specify DYLD_LIBRARY_PATH using buildbot? 为mysql,python和django修改DYLD_LIBRARY_PATH - Modifying DYLD_LIBRARY_PATH for mysql, python, and django 永久添加到MAC上的DYLD_LIBRARY_PATH会导致X11错误 - Permanently adding to DYLD_LIBRARY_PATH on MAC causes X11 errors DYLD_LIBRARY_PATH / LD_LIBRARY_PATH的替代品 - alternatives to DYLD_LIBRARY_PATH/LD_LIBRARY_PATH Matlab Engine Python - 使用iPython的OSx Anaconda Segfault或DYLD_LIBRARY_PATH错误 - Matlab Engine Python - OSx Anaconda Segfault or DYLD_LIBRARY_PATH error with iPython macOS Sierra 上的 python 操作系统和子进程模块不能使用 DYLD_LIBRARY_PATH 和 LD_LIBRARY_PATH - DYLD_LIBRARY_PATH and LD_LIBRARY_PATH cannot be used by python's os and subprocess modules on macOS Sierra dyld:库未加载:@executable_path/../.Python - dyld: Library not loaded: @executable_path/../.Python 如何解决“dyld:库未加载:@executable_path ..”错误 - How to resolve "dyld: Library not loaded: @executable_path.." error 自带系统完整性保护的Mac OS 10.11 El Capitan以来,DYLD_LIBRARY_PATH技巧的替代方法 - Alternative for the DYLD_LIBRARY_PATH-trick since Mac OS 10.11 El Capitan with System Integrity Protection 如何解决dyld:Myo的python包装器中的库未加载错误 - How to solve dyld: Library not loaded error in a python wrapper for a Myo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM