user376507 user376507 -4 years ago 86
Python Question

Setting environment variable in makefile and reading it from python script does not work

I am setting a environment variable (bash) in makefile and I am executing a python script on the next line in the makefile. However, when I try to read the environment variable in the python script using

os.environ.get()
I am unable to read the environment variable. What is the best way to achieve this?

Answer Source

You need to export it in the same line:

target:
        export FOO=bar; python /the/script.py

or

target:
        export FOO=bar; \
        python /the/script.py
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download