Skip to content

fatal error: Python.h: No such file or directory

It looks like you are trying to include the Python.h header file in a C or C++ program, but it is not found on your system. Here are a few things you can try to resolve this error:

  1. Make sure that you have the Python development headers and libraries installed on your system. On Ubuntu, you can install them using the following command:

Install Python development headers on Ubuntu

bash
sudo apt-get install python3-dev

<div class="alert alert-info flex not-prose"> Watch a course Python - The Practical Guide</div>

  1. Check if the Python.h file is present in the expected location. On Debian/Ubuntu systems, the Python.h file is typically located in the /usr/include/pythonX.Y directory, where X and Y are the major and minor version numbers of Python. (For macOS, install via Homebrew with brew install python; for Windows, ensure your build environment includes the Python development headers.)
  2. If the Python.h file is not in the expected location, you may need to specify the correct include path when compiling your program. A more robust approach than hardcoding paths is to use pkg-config to automatically pass the correct flags:

Check if the Python.h file is present in the expected location

bash
gcc $(pkg-config --cflags python3) myprogram.c -o myprogram
  1. If you are using a Makefile to build your program, you may need to update the Makefile to include the correct include path.
  2. If you have installed Python in a non-standard location, you may need to update the environment variables to include the path to the Python headers in the search path.

I hope this helps! Let me know if you have any other questions.

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.