Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"pip install SQLAlchemy" Results in "fatal error: Python.h: No such file or directory"

Calling

pip install SQLAlchemy

I get an error:

lib/sqlalchemy/cextension/processors.c:10:20: fatal error: Python.h: No such file or directory

As far as I know, I have the correct Python version (2.7.3) and OS (Ubuntu 12.04) (See below.) for this to work. Am I doing anything wrong?

The install does work as

pip install --global-option='--without-cextensions' SQLAlchemy"

but I want the C extensions.

Full output:

root@mycomputer:/# pip install SQLAlchemy
Downloading/unpacking SQLAlchemy
  Downloading SQLAlchemy-0.8.3.tar.gz (3.9Mb): 3.9Mb downloaded
  Running setup.py egg_info for package SQLAlchemy

    warning: no files found matching '*.jpg' under directory 'doc'
    no previously-included directories found matching 'doc/build/output'
Installing collected packages: SQLAlchemy
  Running setup.py install for SQLAlchemy
    building 'sqlalchemy.cprocessors' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c lib/sqlalchemy/cextension/processors.c -o build/temp.linux-x86_64-2.7/lib/sqlalchemy/cextension/processors.o
    lib/sqlalchemy/cextension/processors.c:10:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    ***************************************************************************
    command 'gcc' failed with exit status 1
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Failure information, if any, is above.
    Retrying the build without the C extension now.
    ***************************************************************************

    warning: no files found matching '*.jpg' under directory 'doc'
    no previously-included directories found matching 'doc/build/output'
    ***************************************************************************
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Plain-Python build succeeded.
    ***************************************************************************
Successfully installed SQLAlchemy
Cleaning up...
root@mycomputer:/#

Python Version:

root@mycomputer:/#python -V
Python 2.7.3
root@mycomputer:/#

Ubuntu Version:

root@mycomputer:/#cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
root@mycomputer:/#
like image 511
Pat Zabawa Avatar asked Dec 07 '13 01:12

Pat Zabawa


1 Answers

You need to install the python-dev (or similar name) package for your version of Python. It includes all the header files needed to compile C extensions. These files are (unfortunately) not included in the default python packages.

For Ubuntu, the command is

sudo apt-get install python-dev

or

sudo apt-get install python3-dev

depending on which version you're using.

like image 191
MattDMo Avatar answered Oct 31 '22 10:10

MattDMo