1

I have a custom module that needs an library through an environment variable to be set correctly, which I am using in a script.

When I export from commandline and run the script, it works fine:

   export FOO_LIB=/path/to/lib
   python3 myscript.py

However without that, the import foo in my script throws exception:

ImportError: dlopen(/path/to/site-packages/bar.so, 2): Library not loaded: bar.dylib

In my script I tried

os.environ['FOO_LIB'] = '/path/to/lib'
import FOO

I still get the same error.

Is there a way I can do this in the python script itself without having to use bash export at all?

Ufder
  • 527
  • 4
  • 20
  • 1
    Possible duplicate of [How to set environment variables in Python](https://stackoverflow.com/questions/5971312/how-to-set-environment-variables-in-python) – Colin Schoen Dec 06 '18 at 22:55
  • Updated the question to mentioned that I tried `os.environ` without success. – Ufder Dec 06 '18 at 23:43
  • have you tried `os.putenv('FOO_LIB', '/path/to/lib')` ? – Jean-François Fabre Dec 07 '18 at 22:00
  • That library not loaded error is not helpful. `os.environ` should allow you to properly set environment variables. If you are confident the environment variable is not being set please show us a stack trace indicating that. Otherwise we are going to need more context to help you. – Colin Schoen Dec 08 '18 at 19:23

0 Answers0