• Re: [Help Request] Embedding Python in a CPP Application Responsibly &

    From Dieter Maurer@21:1/5 to John McCardle on Thu Jan 26 08:50:51 2023
    John McCardle wrote at 2023-1-25 22:31 -0500:
    ...
    1) To get the compiled Python to run independently, I have to hack >LD_LIBRARY_PATH to get it to execute. `LD_LIBRARY_PATH=./Python-3.11.1 >./Python-3.11.1/python` .

    The need to set `LD_LIBRARY_PATH` usually can be avoided via
    a link time option: it tells the linker to add library path
    information into the created shared object.

    Read the docs to find out which option this is (I think it
    was `-r` but I am not sure).

    Even when trying to execute from the same
    directory as the binary & executable, I get an error, `/python: error
    while loading shared libraries: libpython3.11.so.1.0: cannot open shared >object file: No such file or directory`.

    It might be necessary, to provide the option mentioned above
    for all shared libraries involved in your final application.

    Alternatively, you could try to put the shared objects
    into a stadard place (searched by default).

    2) When running the C++ program that embeds Python, I see these messages >after initializing:
    `Could not find platform independent libraries <prefix>
    Could not find platform dependent libraries <exec_prefix>`

    Again: either put your installation in a standard place
    or tell the Python generation process about your non-standard place.


    This is seemingly connected to some issues regarding libraries: When I
    run the Python interpreter directly, I can get some of the way through
    the process of creating a virtual environment, but it doesn't seem to
    leave me with a working pip:

    `$ LD_LIBRARY_PATH=./Python-3.11.1 ./Python-3.11.1/python
    import venv
    venv.create("./venv", with_pip=True)
    subprocess.CalledProcessError: Command >'['/home/john/Development/7DRL/cpp_embedded_python/venv/bin/python',
    '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit >status 127.`

    Run the command manually and see what errors this gives.

    ...

    3) I'm not sure I even need to be statically linking the interpreter.

    There should be no need (if all you want in the embedding).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)