error fatal: Python.h: No hay tal archivo o directorio


Estoy tratando de construir una biblioteca compartida usando un archivo de extensión C, pero primero tengo que generar el archivo de salida utilizando el comando a continuación:

gcc -Wall utilsmodule.c -o Utilc

Después de ejecutar el comando, recibo este mensaje de error:

Utilsmodule.c: 1: 20: error fatal: Python.h: No hay tal archivo o directorio compilación terminada.

De hecho, he intentado todas las soluciones sugeridas a través de Internet, pero el problema todavía existe ... también tengo ningún problema con Python.h. Me las arreglé para localice el archivo en mi máquina ... ¿alguien ha enfrentado el mismo problema antes??

Author: Chris, 2014-02-03

25 answers

Parece que no ha instalado correctamente los archivos de cabecera y las bibliotecas estáticas para python dev. Utilice su gestor de paquetes para instalarlos en todo el sistema.

Para apt (Ubuntu, Debian...):

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

Para yum (CentOS, RHEL...):

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

Para dnf (Fedora...):

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

Para zypper (openSUSE...):

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

Para 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

Para apt-cyg ( Cygwin...):

apt-cyg install python-devel   # for python2.x installs
apt-cyg install python3-devel  # for python3.x installs
 1447
Author: wim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-18 14:56:11

En Ubuntu, estaba ejecutando Python 3 y tuve que instalar

sudo apt-get install python3-dev

Si desea utilizar una versión de Python que no esté vinculada a python3, instale el python3 asociado.paquete x-dev. Por ejemplo:

sudo apt-get install python3.5-dev
 236
Author: FreshPow,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-28 18:49:03

Dos cosas que tienes que hacer.

Instalar el paquete de desarrollo para Python, en el caso de Debian / Ubuntu / Mint se hace con el comando:

sudo apt-get install python-dev

Lo segundo es que los archivos include no están de forma predeterminada en la ruta include, ni la biblioteca de Python está vinculada con el ejecutable de forma predeterminada. Necesita agregar estas banderas (reemplace la versión de Python en consecuencia):

-I/usr/include/python2.7 -lpython2.7 

En otras palabras, tu comando compile debería ser:

gcc -Wall -I/usr/include/python2.7 -lpython2.7  utilsmodule.c -o Utilc 
 55
Author: vartec,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-03 15:13:31

Si está utilizando una Raspberry Pi:

sudo apt-get install python-dev
 44
Author: Malachi Bazar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-16 02:50:23

En Fedora ejecute esto para Python 2:

sudo dnf install python2-devel

Y para Python 3:

sudo dnf install python3-devel
 31
Author: ravi.zombie,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-22 15:24:05

Si está utilizando tox para ejecutar pruebas en varias versiones de Python, es posible que deba instalar las bibliotecas de desarrollo de Python para cada versión de Python en la que esté realizando pruebas.

sudo apt-get install python2.6-dev 
sudo apt-get install python2.7-dev 
etc.
 26
Author: Christian Long,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-28 18:13:44

Me gustaría añadir también la solución para Cygwin:

Necesita instalar el paquete python2-devel o python3-devel, dependiendo de la versión de Python que estés usando.

Puede instalarlo rápidamente usando 32-bit o 64-bit setup.exe (dependiendo de su instalación) de Cygwin.com .

Ejemplo (modifica el nombre de archivo de setup.exe y la versión principal de Python si es necesario):

$ setup.exe -q --packages=python3-devel

También puede comprobar mi otra respuesta para un pocas opciones más para instalar los paquetes de Cygwin desde la línea de comandos.

 21
Author: Dawid Ferenczy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-08 11:31:30

En AWS API (CentOS) su

yum install python27-devel
 18
Author: yespbs,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-09 14:29:47

Para mí, cambiarlo a esto funcionó:

#include <python2.7/Python.h>

Encontré el archivo /usr/include/python2.7/Python.h, y dado que /usr/include ya está en la ruta de inclusión, entonces python2.7/Python.h debería ser suficiente.

También puede agregar la ruta de inclusión desde la línea de comandos en su lugar - gcc -I/usr/lib/python2.7 (gracias @erm3nda).

 18
Author: sashoalm,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-29 08:14:06

Asegúrese de que los archivos de desarrollo de Python vienen con su sistema operativo.

No debe codificar la biblioteca e incluir rutas de acceso. En su lugar, use pkg-config, que mostrará las opciones correctas para su sistema específico:

$ pkg-config --cflags --libs python2
-I/usr/include/python2.7 -lpython2.7

Puede agregarlo a su línea gcc:

gcc $(pkg-config --cflags --libs python2) -Wall utilsmodule.c -o Utilc
 14
Author: sleblanc,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-03 15:26:32

Instalación de AWS EC2 ejecutando python34:

sudo yum install python34-devel

 14
Author: orsonady,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-12 22:57:40

No Es la misma situación, pero también funciona para mí y ahora puedo usar TRAGO con Python3.5:

Estaba tratando de compilar:

gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/

Con Python 2.7 funciona bien, no con mi versión 3.5:

Existe_wrap.c: 147: 21: error fatal: Python.h: No existe el archivo o el directorio compilación terminada.

Después de ejecutar en mi instalación Ubuntu 16.04:

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

Ahora puedo compilar sin problemas Python3.5:

gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
 13
Author: Hugo L.M,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-05 12:11:03

En mi caso, lo que lo arregló en Ubuntu fue instalar los paquetes libpython-all-dev (o libpython3-all-dev si usas Python 3).

 12
Author: Oriol Nieto,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-01 01:27:33

Si usa un virtualenv con un python 3.6 (edge ahora mismo), asegúrese de instalar el python 3.6 dev sudo apt-get install python3.6-dev correspondiente, de lo contrario ejecutando sudo python3-dev instalará el python dev 3.3.3-1, lo que no resolverá el problema.

 12
Author: Guillaume Cisco,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-09 11:46:54

Logré resolver este problema y generar el archivo .so en un comando

gcc -shared -o UtilcS.so
-fPIC -I/usr/include/python2.7 -lpython2.7  utilsmodule.c
 11
Author: Mohanad Y.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-29 01:43:48

Pruebe apt-file. Es difícil recordar el nombre del paquete donde reside el archivo que falta. Es genérico y útil para cualquier archivo de paquete.

Por ejemplo:

root@ubuntu234:~/auto# apt-file search --regexp '/Python.h$'
pypy-dev: /usr/lib/pypy/include/Python.h
python2.7-dbg: /usr/include/python2.7_d/Python.h
python2.7-dev: /usr/include/python2.7/Python.h
python3.2-dbg: /usr/include/python3.2dmu/Python.h
python3.2-dev: /usr/include/python3.2mu/Python.h
root@ubuntu234:~/auto# 

Ahora puedes hacer una conjetura experta en cuanto a cuál elegir.

 9
Author: Venfah Nazir,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-03 12:43:21

Para los camaradas de openSUSE:

sudo zypper install python3-devel
 8
Author: kmonsoor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-29 05:47:51

Para CentOS 7:

sudo yum install python36u-devel

Seguí las instrucciones aquí para instalar python3.6 en varias máquinas virtuales: https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-centos-7 y luego fue capaz de construir mod_wsgi y conseguir que funcione con un python3.6 virtualenv

 8
Author: Steve G,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-27 16:41:18

También encontré este error cuando estaba instalando coolprop en ubuntu.

Para ubuntu 16.04 con python 3.6

sudo apt-get install python3.6-dev

Si alguna vez esto no funciona, intente instalar/actualizar gcc lib.

sudo apt-get install gcc
 6
Author: Wreeecks,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-14 01:58:00

Este error ocurrió cuando intenté instalar ctds en CentOS 7 con Python3.6. Hice todos los trucos mencionados aquí, incluyendo yum install python34-devel. El problema fue Python.h se encontró en /usr/include/python3.4m but not in /usr/include/python3.6m. Traté de usar --global-option para apuntar a incluir dir (pip3.6 install --global-option=build_ext --global-option="--include-dirs=/usr/include/python3.4m" ctds). Esto resultó en un lpython3.6m no encontrado al vincular ctds.

Finalmente lo que funcionó fue arreglar el entorno de desarrollo para Python3.6 necesita corregir con la inclusión y libs.

yum -y install https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/python36u-libs-3.6.3-1.ius.centos7.x86_64.rpm

Python.h necesita estar en su ruta de inclusión para gcc. Cualquiera que sea la versión de python utilizada, por ejemplo si es 3.6, entonces debería estar en /usr/include/python3.6m/Python.h típicamente.

 4
Author: Babu Arunachalam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-04 06:19:26

Sure python-dev or libpython-all-dev are the first thing to (apt )install, pero si eso no ayuda como fue mi caso, le aconsejo que instale los paquetes foreign Function Interface por sudo apt-get install libffi-dev y sudo pip install cffi.

Esto debería ayudar especialmente si ves el error como/from c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory.

 4
Author: Huge,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-22 20:35:17

A menudo aparece cuando intenta eliminar python3.5 e instalar python3.6.

Así que al usar python3 (que python3 -V => python3.6) para instalar algunos paquetes requerido python3.5 encabezado aparecerá este error.

Resolver mediante el módulo install python3.6-dev.

 2
Author: dphans,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-14 07:38:00

Esto significa que Python.h no está en las rutas de inclusión predeterminadas de su compilador. ¿Lo ha instalado en todo el sistema o localmente? ¿Cuál es tu sistema operativo?

Podría usar la bandera -I<path> para especificar un directorio adicional donde su compilador debería buscar encabezados. Probablemente tendrá que hacer un seguimiento con -L<path> para que gcc pueda encontrar la biblioteca con la que estará enlazando usando -l<name>.

 1
Author: Kos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-03 15:12:09

Si está utilizando Python 3.6 en Amazon Linux (basado en RHEL, pero las respuestas de RHEL dadas aquí no funcionaron):

sudo yum install python36-devel
 1
Author: Yigal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-13 13:56:21

A veces, incluso después de instalar python - dev, el error persiste, Compruebe el error si falta 'gcc'.

Primera descarga como se indica en https://stackoverflow.com/a/21530768/8687063 , luego instale gcc

Para apt (Ubuntu, Debian...):

sudo apt-get install gcc

Para yum (CentOS, RHEL...):

sudo yum install gcc

Para dnf (Fedora...):

sudo dnf install gcc

Para zypper (openSUSE...):

sudo zypper in gcc

Para apk (Alpino...):

sudo apk gcc
 1
Author: HimanshuGahlot,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-06-28 00:41:05