views:

519

answers:

3

I downloaded the latest version of Boost and I'm trying to get the Boost.python tutorial up and running on Ubuntu 10.04: http://www.boost.org/doc/libs/1_43_0/libs/python/doc/tutorial/doc/html/python/hello.html

I navigated to the correct directory, ran "bjam" and it compiled using default settings. I did not yet create a bjam config file. The compilation appears to have worked, but now I have no idea how to include the files in my python script. When I try to run the python hello world script, it gives me this error:

Traceback (most recent call last):
  File "./hello.py", line 6, in <module>
    import hello_ext
ImportError: libboost_python.so.1.43.0: cannot open shared object file: No such file or  directory

Anyone know what is going on?

A: 

Did you install boost? Just compiling it isn't sufficient to install the libraries where they need to be to run programs.

Noah Roberts
Yeah, installed boost. Included the boost header files in my c++ module, and used bjam to compile. I'm pretty sure that's all working correctly. I just need figure out how to import it into python now.
Doughy
+1  A: 

I have no experience with the the Boost Python libraries but as the error states, it is unable to find the libboost_python shared object.

You have several options here (there may be more):

  1. Place the .so in /usr/local/lib.
  2. Place the .so in /usr/lib. This is probably a bad idea.
  3. Run export LD_LIBRARY_PATH=/path_to_so/ before execution.
Soo Wei Tan
Can I just place it in the same directory as my python script?
Doughy
No you can't... in Windows the DLL loading procedure starts looking for DLLs in the folder of execution, but in Linux nothing like that happens (to the best of my knowledge).
Soo Wei Tan
+2  A: 

How did you install boost ? Assuming you have use the following: http://www.boost.org/doc/libs/1_43_0/more/getting_started/unix-variants.html#easy-build-and-install

liboost_python shard library will be install in /usr/local/lib

To run the hello.py example, try the following:

LD_LIBRARY_PATH=/usr/local/lib python ./hello.py
Patrice Tisserand
OK, that got it working. Thanks. Can you explain why I can't run this without the LD_LIBRARY_PATH?
Doughy
In section DESCRIPTION of man ld.so, you have the following information:- The necessary shared libraries needed by the program are searched for in the following order:- Using the environment variable LD_LIBRARY_PATH- From the cache file /etc/ld.so.cache which contains a compiledlist of candidate libraries previously found in the augmented library path- In the default path /lib, and then /usr/lib.Since your boot shared library are installed in /usr/local/lib, you have the following option:- use LD_LIBRARY_PATH or - add /usr/local/lib to your shared library cache (see man ldconfig)
Patrice Tisserand