Home > Backend Development > Python Tutorial > How to Fix 'fatal error: Python.h: No such file or directory' When Building C Extensions?

How to Fix 'fatal error: Python.h: No such file or directory' When Building C Extensions?

Linda Hamilton
Release: 2024-12-15 10:12:12
Original
700 people have browsed it

How to Fix

Troubleshoot "fatal error: Python.h: No such file or directory" in Building C Extensions

When attempting to build a shared library with a C extension, one may encounter the following error:

utilsmodule.c:1:20: fatal error: Python.h: No such file or directory
compilation terminated.
````

Addressing this error requires verifying the installation of Python header files and static libraries for development (dev). Depending on the operating system, the appropriate package manager should be employed for installation.

**Package Managers:**

* **apt (Ubuntu, Debian)**
  * `sudo apt-get install python-dev` (for python2.x)
  * `sudo apt-get install python3-dev` (for python3.x)

* **yum (CentOS, RHEL)**
  * `sudo yum install python-devel` (for python2.x)
  * `sudo yum install python3-devel` (for python3.x)

* **dnf (Fedora)**
  * `sudo dnf install python2-devel` (for python2.x)
  * `sudo dnf install python3-devel` (for python3.x)

* **zypper (openSUSE)**
  * `sudo zypper in python-devel` (for python2.x)
  * `sudo zypper in python3-devel` (for python3.x)

* **apk (Alpine)**
  * `sudo apk add python2-dev` (for python2.x)
  * `sudo apk add python3-dev` (for python3.x)

* **apt-cyg (Cygwin)**
  * `apt-cyg install python-devel` (for python2.x)
  * `apt-cyg install python3-devel` (for python3.x)
Copy after login

The above is the detailed content of How to Fix 'fatal error: Python.h: No such file or directory' When Building C Extensions?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template