How to incorporate environment from with python.

Peter J. Holzer hjp-python at hjp.at
Sun Mar 22 12:44:53 EDT 2020


On 2020-03-22 16:04:59 +0100, Antoon Pardon wrote:
> $ /opt/csw/bin/python
> Python 2.6.4 (r264:75706, Sep  9 2015, 15:05:38) [C] on sunos5
> Type "help", "copyright", "credits" or "license" for more information.

Hmm. Solaris

> As you can see the import works in the second session because I
> had done the needed assignments and exports in bash.
> 
> Now I was wondering, if I could do those kind of preparations in python.
> I would like to start python from an unprepared bash, and do the necessary
> stuff to make the import work.
> 
> I already tried changing os.environ and using os.putenv, but that didn't
> seem to work.

I remember that once upon a time setting LD_LIBRARY_PATH had no effect
on the process itself (only on child processes) on 64 bit Linux, because
the runtime saved that value before loading the first shared library.
Maybe Solaris does the same?

In this case it might help to reexec the program. Something like

    if "ORACLE_HOME" not in os.environ:
        # Need to set env and reexec
        os.environ["ORACLE_HOME"] = ...
        os.environ["LD_LIBRARY_PATH"] = ...
        ...

        os.execv(sys.argv[0], sys.argv)

    # real content starts here

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20200322/ae4fd303/attachment.sig>


More information about the Python-list mailing list