Thanks to visit codestin.com
Credit goes to github.com

Skip to content

How to add an environment variable LD_LIBRARY_PATH to the python code and effective #100567

Closed as not planned
@zjl767864079zjl

Description

@zjl767864079zjl

I add LD_LIBRARY_PATH to the python code like:

test.py

import os
from ctypes import CDLL

os.environ['LD_LIBRARY_PATH'] = "/home/test/myfolder/pyfolder/ztools1226/lib"
print(os.environ)
s_dll_path = f"/home/test/myfolder/pyfolder/ztools1226/lib/libCityPlanParse.so"
dll_load = CDLL(s_dll_path)

I print the os.environ the LD_LIBRARY_PATH value already exists,but when I CDLL /home/test/myfolder/pyfolder/ztools1226/lib/libCityPlanParse.so report an error:
OSError: libCityPlanParse.so: cannot open shared object file: No such file or directory

But when I join in the command-line "export LD_LIBRARY_PATH=/home/test/myfolder/pyfolder/ztools1226/lib" before executing test.py,program execution ok.

So the environment variable I added in the code is not take effect.But I need to do that.How can I write about it to take effect?

My environment

python 3.8.3
Linux system

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions