How to use `env python3` and save the calling environment?

I have a problem with OSX that #!/usr/bin/env python3causes environment variables such as library paths (e.g. LD_LIBRARY_PATH). On Linux, it works correctly.

Reading the man page on envdoes not seem to be happening. I only need to modify the environment, if I ask for it, but I do not.

What is a shebang portable string that saves the environment?

Note. I find the problem, because the call subprocess.opento one of my programs out of order because it can not find one of the libraries. However, if I run python interactively, the same call works fine.

+4
source share
1 answer

This is the X OS the System Here Integrity Protection at work; some "dangerous" environment variables, such as DYLD_LIBRARY_PATH, and, as you have discovered, LD_LIBRARY_PATHare not transmitted to any binary file using the path /usr/binor /bin.

Thus, it /usr/bin/envnever sees any of several environment variables and cannot pass them to the child process python3that it spawns.

See a few other related posts:

subprocess, shebang, env, env.

+3

Source: https://habr.com/ru/post/1668129/


All Articles