4

I am trying to build the boost python library on my ubuntu. However, when I execute

./b2 --with-python

It always returns me errors related to

./boost/python/detail/wrap_python.hpp:57:11: fatal error: pyconfig.h: No such file or directory
 # include <pyconfig.h>
           ^~~~~~~~~~~~

I tried to look up online, e.g., https://github.com/boostorg/build/issues/289

Follow their suggestion I check my "project-config.jam" And I found

# Python configuration
import python ;
if ! [ python.configured ]
{
    using python : 3.7 : /home/lowlimb/anaconda3 :/home/lowlimb/anaconda3/include/python3.7m;
}

Which is correct, thus I really don't know how to fix this issue. Can anyone provide me some advice?

HAO LEE
  • 153
  • 3
  • 13

3 Answers3

4

In addition to installing the python dev libs as suggested by the other answers, you can specify the python path directly:

CPLUS_INCLUDE_PATH=/usr/include/python3.7 make

Or in your case something like:

CPLUS_INCLUDE_PATH=/home/lowlimb/anaconda3/include/python3.7 ./b2

This worked for me when compiling a projects using Boost Python where I got the same error.

Marius
  • 380
  • 3
  • 10
3

pyconfig.h is installed with sudo apt install python-dev

To build with a specific python version, you can do

./bootstrap.sh --with-python=<path to python>

e.g.

./bootstrap.sh --with-python=python3

to use your system's python3 or

./bootstrap.sh --with-python=$VIRTUAL_ENV/bin/python

to use the python from your virtual environment.

1

In order to build Boost-Python or more generally, use Python from C/C++, you need the Python development files:

$ sudo apt install python3.7-dev
rustyx
  • 80,671
  • 25
  • 200
  • 267