Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to build a shared library using a C extension file but first I have to generate the output file using the command below:

gcc -Wall utilsmodule.c -o Utilc 

After executing the command, I get this error message:

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

I have tried all the suggested solutions over the internet but the problem still exists. I have no problem with Python.h. I managed to locate the file on my machine.

like image 796
Mohanad Y. Avatar asked Feb 03 '14 15:02

Mohanad Y.


People also ask

How to Fix fatal error python h No such file or directory?

Python h no such file or directory is a fatal error. If you are trying to build a shared library using a C extension file, you need to install the development version of Python. For example, if you use Python 3, you need to install the python3-dev.

What is python h file?

Python.h is nothing but a header file. It is used by gcc to build applications. You need to install a package called python-dev. This package includes header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications.

What is python3 Dev?

python-dev is the package that contains the header files for the Python C API, which is used by lxml because it includes Python C extensions for high performance.


1 Answers

Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.

For apt (Ubuntu, Debian...):

sudo apt-get install python-dev   # for python2.x installs sudo apt-get install python3-dev  # for python3.x installs 

For yum (CentOS, RHEL...):

sudo yum install python-devel    # for python2.x installs sudo yum install python3-devel   # for python3.x installs 

For dnf (Fedora...):

sudo dnf install python2-devel  # for python2.x installs sudo dnf install python3-devel  # for python3.x installs 

For zypper (openSUSE...):

sudo zypper in python-devel   # for python2.x installs sudo zypper in python3-devel  # for python3.x installs 

For apk (Alpine...):

# This is a departure from the normal Alpine naming # scheme, which uses py2- and py3- prefixes sudo apk add python2-dev  # for python2.x installs sudo apk add python3-dev  # for python3.x installs 

For apt-cyg (Cygwin...):

apt-cyg install python-devel   # for python2.x installs apt-cyg install python3-devel  # for python3.x installs 
like image 177
wim Avatar answered Oct 17 '22 23:10

wim