20

Trying to install Cython on a small VPS running Ubuntu Server. Did

sudo apt-get install gcc

and then

python setup.py install

In the Cython directory, but I get this peculiar error.

running install
running build
running build_py
running build_ext
building 'Cython.Plex.Scanners' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c Cython/Plex/Scanners.c -o build/temp.linux-x86_64-2.6/Cython/Plex/Scanners.o
Cython/Plex/Scanners.c:4:20: error: Python.h: No such file or directory
Cython/Plex/Scanners.c:6:6: error: #error Python headers needed to compile C extensions, please install development version of Python.
error: command 'gcc' failed with exit status 1

Why should I need a 'development version of Python'? Running Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41). Thanks!

DizzyDoo
  • 1,489
  • 6
  • 21
  • 32

2 Answers2

37

You need the developer version of Python - i.e. the Python header files (Python.h)

sudo apt-get install python-dev
user225312
  • 126,773
  • 69
  • 172
  • 181
  • Okay! May I ask why this is necessary? My development machine (Windows) just has the standard Python 2.6 and works okay. Then again, I installed via the packaged installer, so it might have included everything. – DizzyDoo Dec 15 '10 at 13:20
  • A simple answer would be that some source files in Cython #include some python header files and so you need python headers to compile Cython. If you want to know why those files are being used then you need to look at Cython source. – binW Dec 15 '10 at 13:30
  • 1
    This is also due to the fact that Ubuntu and Debian choose to separate the devel packages. – user225312 Dec 15 '10 at 14:39
  • 3
    The standard Windows distribution includes the header files. On certain linuxes, the default installation doesn't (because the distibutors think it's funny to omit them, along with. e.g. parts of the stdlib (tkinter) :/). –  Dec 15 '10 at 14:56
  • I simply installed `python-devel` in CentOS 7. It may be necessary to know the Python version required in the OS – Oluwatobi Samuel Omisakin Jul 11 '18 at 15:04
4

You need the headers included in the development version of Python, i.e. python.h. It should be packaged in Ubuntu as python-dev.

asthasr
  • 9,125
  • 1
  • 29
  • 43