Ubuntu 10.04中的Boost.Python教程

2 投票
3 回答
4674 浏览
提问于 2025-04-15 23:45

我下载了最新版本的Boost,想在Ubuntu 10.04上运行Boost.python的教程:http://www.boost.org/doc/libs/1_43_0/libs/python/doc/tutorial/doc/html/python/hello.html

我找到了正确的目录,运行了“bjam”,它用默认设置进行了编译。还没有创建bjam配置文件。编译看起来是成功的,但我现在不知道怎么在我的python脚本中包含这些文件。当我尝试运行python的hello world脚本时,出现了这个错误:

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

有人知道发生了什么吗?

3 个回答

0

你安装了boost吗?光编译它是不够的,还需要把库安装到程序运行所需的位置。

2

我对Boost Python库没有经验,但根据错误信息,它找不到libboost_python这个共享库。

你有几个选择(可能还有更多):

  1. 把这个.so文件放到/usr/local/lib目录下。
  2. 把这个.so文件放到/usr/lib目录下。这可能不是个好主意。
  3. 在执行之前运行 export LD_LIBRARY_PATH=/path_to_so/
5

你是怎么安装boost的?

假设你使用了以下链接中的方法:http://www.boost.org/doc/libs/1_43_0/more/getting_started/unix-variants.html#easy-build-and-install

libboost_python这个共享库会被安装在/usr/local/lib目录下。

要运行hello.py这个示例,可以尝试以下操作:

LD_LIBRARY_PATH=/usr/local/lib python ./hello.py

撰写回答