How to fix fatal error: Python.h: No such file or directory?

Better Stack Team
Updated on February 3, 2023

This error typically occurs when the development headers for Python are not installed on your system. To fix this error, you need to install the python-dev package, which contains the necessary headers.

On Ubuntu or Debian:

sudo apt-get install python-dev

On CentOS or Red Hat:

sudo yum install python-devel

On Windows: You need to install the Visual C++ Build Tools and then install the python development package using pip

pip install --upgrade setuptools
pip install --upgrade wheel
pip install --upgrade python-dev

Once you have installed the development headers, you should be able to run your script without encountering the fatal error.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →