Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot build boost python library (fatal error: pyconfig.h: No such file or directory)

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?

like image 971
HAO LEE Avatar asked May 17 '26 17:05

HAO LEE


2 Answers

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.

like image 69
Marius Avatar answered May 20 '26 06:05

Marius


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.

like image 39
Maxim Dolgov Avatar answered May 20 '26 05:05

Maxim Dolgov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!