Run a python module in MOOSE

227 views
Skip to first unread message

Sang Inn Woo

unread,
Feb 2, 2016, 11:28:24 AM2/2/16
to moose-users
Hello,

I tried to run a python module in Moose.
To test, I have made a custom post-processor module which includes a code to call python function.
However, whenever Moose call this post-processor, I have encountered the following error message.

I have attached the post-processor code here.
(I am running the Moose in Mac)

Best Regards,

Sang Inn Woo



dyld: lazy symbol binding failed: Symbol not found: _Py_Initialize

Referenced from: /Users/sanginnwoo/projects/longtailedtit/lib/liblongtailedtit-opt.0.dylib

Expected in: flat namespace


dyld: Symbol not found: _Py_Initialize

Referenced from: /Users/sanginnwoo/projects/longtailedtit/lib/liblongtailedtit-opt.0.dylib

Expected in: flat namespace

TransferringDataPostProcessor.C
TransferringDataPostProcessor.h

Cody Permann

unread,
Feb 2, 2016, 11:48:47 AM2/2/16
to moose-users
Looks like you need to make additional libraries available in your run-time environment. When using dynamic loading, those libraries don't necessarily need to exist during linking but they need to be around when they are called during runtime. Most of us don't link Python directly to our compiled C++ code but a little Googling should help you locate those missing links.

Cody

--
You received this message because you are subscribed to the Google Groups "moose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moose-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/moose-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/moose-users/f50d7dae-8569-4509-9a2e-f4baf1bb89fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hans Hammer

unread,
Feb 2, 2016, 2:14:09 PM2/2/16
to moose-users
You can find out, which libs your program tries to load with

ldd executable

You can than add the missing lib with

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lib

where you only specify the folder, the lib is located. Since you use the MOOSE environment, your Python installation is not in the default location and most likely not found.

Some more reading on this:
http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

Hans

Miller, Jason M

unread,
Feb 3, 2016, 9:35:42 AM2/3/16
to moose...@googlegroups.com
I just wanted to add to Hans email a bit:

On Tue, Feb 2, 2016 at 12:14 PM, Hans Hammer <hans....@tamu.edu> wrote:
You can find out, which libs your program tries to load with

ldd executable


Macintosh users:

otool -L executable
 
You can than add the missing lib with

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lib


Macintosh users:

 export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/path/to/dylib

Please keep in mind as well, if you are running OS X 10.11 (El Capitan), Apple has done away with allowing DYLD_LIBRARY_PATH being read within the environment due to security reasons. You either must find a way to have your binary linked to your library during build time (guys help me out on the proper term for this if I am wrong), or place the library in /usr/local/lib. A location which Apple has continued to prepend library searching during execution time of binary -automatically-. If you place a dylib in this location, there is no need to do anything in your environment.

 

 

Cody Permann

unread,
Feb 3, 2016, 9:40:39 AM2/3/16
to moose...@googlegroups.com
On Wed, Feb 3, 2016 at 7:35 AM Miller, Jason M <jason....@inl.gov> wrote:
I just wanted to add to Hans email a bit:

On Tue, Feb 2, 2016 at 12:14 PM, Hans Hammer <hans....@tamu.edu> wrote:
You can find out, which libs your program tries to load with

ldd executable


Macintosh users:

otool -L executable
 
You can than add the missing lib with

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lib


Macintosh users:

 export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/path/to/dylib

Please keep in mind as well, if you are running OS X 10.11 (El Capitan), Apple has done away with allowing DYLD_LIBRARY_PATH being read within the environment due to security reasons. You either must find a way to have your binary linked to your library during build time (guys help me out on the proper term for this if I am wrong),

Close! The proper way to do this is to set an "rpath" for every external library your application requires, or you can put the library in the system location (not recommended).
 

Sang Inn Woo

unread,
Feb 3, 2016, 10:55:19 AM2/3/16
to moose-users
Hans, Miller, and Cody,

Thank you for your comments! 
I am a novice in programming in linux (I t am familiar to .net in windows); 
I don't know exactly how to set an external library in linux or Mac (I'm actually using Mac)

Would you please give me a brief idea how to and where to add following when compiling and linking a Moose app? 

"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lib"

Have a nice day!

Sang Inn Woo

Cody Permann

unread,
Feb 3, 2016, 11:21:57 AM2/3/16
to moose...@googlegroups.com
On Wed, Feb 3, 2016 at 8:55 AM Sang Inn Woo <sangi...@gmail.com> wrote:
Hans, Miller, and Cody,

Thank you for your comments! 
I am a novice in programming in linux (I t am familiar to .net in windows); 
I don't know exactly how to set an external library in linux or Mac (I'm actually using Mac)

Would you please give me a brief idea how to and where to add following when compiling and linking a Moose app? 

"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lib"

This is an environment variable. You'd type it right on the command line or put it in your bash initialization file (.bash_profile on Macs or .bashrc_local on most Linux boxes). However as Jason pointed out, this doesn't work with El Capitan in which case you'd have to add extra flags to the Makefile to add in additional "rpath" arguments. So what version of OS X are you working with?
 

Sang Inn Woo

unread,
Feb 3, 2016, 11:37:01 AM2/3/16
to moose-users
Cody,

I am working with El Capitan, unfortunately.
Then I may need to add extra flags to the Makefile according to Jason.
(I have attached the "Makefile" for my Moose App (named as longtailedtit) here)

Best Regards,

Sang Inn Woo
Makefile

Sang Inn Woo

unread,
Feb 3, 2016, 12:59:41 PM2/3/16
to moose-users
One more questions:

After installing Moose, the default python module changes. (I guess the python modules in "opt/moose/miniconda")
How can I need to include "opt/moose/miniconda/include/python2.7/Python.h" instead of "python2.7/Python.h"?
(It can be a very basic question, but please let me know)

Miller, Jason M

unread,
Feb 3, 2016, 1:15:17 PM2/3/16
to moose...@googlegroups.com
For what ever purpose you are attempting to gather the includes and libraries python is currently using, you should incorporate the use of   python-config

Particularly the command you are probably looking for is as follows:

#> python-config --ldflags --includes
-lpython2.7 -ldl -framework CoreFoundation -u _PyMac_Error
-I/opt/moose/miniconda/include/python2.7 -I/opt/moose/miniconda/include/python2.7 

Note, that if you performed a `module purge`, that is to not use the Python interpreter supplied by our moose-environment package you installed, you will get link lines instead to your system supplied Python interpreter:

#> module purge
#> python-config --ldflags --includes
-L/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -lpython2.7 -ldl -framework CoreFoundation
-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7


So keep that in mind as well when linking to Python libraries.

Hope this helps!
Jason



--
You received this message because you are subscribed to the Google Groups "moose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moose-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/moose-users.

Sang Inn Woo

unread,
Feb 4, 2016, 8:50:31 PM2/4/16
to moose-users
Jason, Cody, and Hanns

Thank you for your comment! You're really helpful.

I have found the flags for compiling and linking to couple Python code in C++.
For a simple C++ code (with Python.h), I have succeeded to run it.
Now, I am looking the Makefile and Moose code to figure out where I need to put these flags.
I will update it after I get it.

Have a nice day!

Sang Inn Woo


Reply all
Reply to author
Forward
0 new messages