Coding⏱️ 2 min read📅 2026-05-30

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

Error in C extension file compilation due to missing Python.h file.

Quick Answer: Ensure you have installed the Python development package that includes Python.h, and try recompiling your code with the -I flag to specify the include directory.

To resolve the 'fatal error: Python.h: No such file or directory' issue, you need to install the Python development package that includes the Python header files. This is typically done using a package manager like apt-get on Ubuntu-based systems or brew on macOS.

🛠️ Step-by-Step Verified Fixes

Method 1: Install Python Development Package

  1. Step 1: Open a terminal and run the command sudo apt-get install python3-dev for Ubuntu-based systems or brew install python for macOS.

Method 2: Install Python Development Package using pip

  1. Step 1: Open a terminal and run the command pip install py-cpython.

💡 Conclusion

Once you have installed the Python development package, re-run your gcc command to compile and link your C extension file.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions