Set LD_LIBRARY_PATH before importing in python

后端 未结 5 763
鱼传尺愫
鱼传尺愫 2020-12-05 13:08

Python uses the PYTHONPATH environment-variable to determine in which folders it should look for modules. You can play around with it by modifying sys.pat

5条回答
  •  隐瞒了意图╮
    2020-12-05 13:44

    UPDATE: see the EDIT below.

    I would use:

    import os
    
    os.environ['LD_LIBRARY_PATH'] = os.getcwd()  # or whatever path you want
    

    This sets the LD_LIBRARY_PATH environment variable for the duration/lifetime of the execution of the current process only.

    EDIT: it looks like this needs to be set before starting Python: Changing LD_LIBRARY_PATH at runtime for ctypes

    So I'd suggest going with a wrapper .sh (or .py if you insist) script. Also, as @chepner pointed out, you might want to consider installing your .so files in a standard location (within the virtualenv).

    See also Setting LD_LIBRARY_PATH from inside Python

提交回复
热议问题