Home > Uncategorized > Setting LD_LIBRARY_PATH in Python

Setting LD_LIBRARY_PATH in Python

I have a python module entirely written in C++ with third party dependencies not in LD_LIBRARY_PATH nor ldconfig. Let’s say


I want to use this module without writing a shell script to set LD_LIBRARY_PATH. Here is how to do:

import sys, os
mymodule_path = "/home/me/python/mymodule"
    import mymodule
except ImportError:
   if sys.platform == 'win32':
       os.environ['PATH'] = mymodule_path
   elif sys.platform == 'darwin':
       os.environ['DYLD_LIBRARY_PATH'] = mymodule_path
       os.environ['LD_LIBRARY_PATH'] = mymodule_path
   args = [sys.executable]
   os.execv(sys.executable, args)
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: