Error : python.h : no such file or directory

Adrian Eyre a.eyre at optichrome.com
Wed Mar 15 07:43:38 EST 2000


> #include <python.h>

I think this should be "Python.h" not "python.h"

> #include <stdio.h>
> #include <stdlib.h>
> 
> PyObject * getres(PyObject * self, PyObject * args);

Make this do something, or you'll have an unresolved external. e.g.:

PyObject* getres(PyObject* self, PyObject* args)
{
	printf("Hello world\n");
}

> static PyMethodDef resMethods[]=
> {
> {"getresult", getres, METH_VARARGS},
> {NULL}

This may need to be: { NULL, NULL }

> void initres()
> {
>     (void) Py_Initmodule ("res", resMethods);
> }

That bit seems okay.

> int getresult
> {
>     printf("enter 2 numbers\n");
>     scanf("%d %d", &x,&y);
>     z=x*y;
>     printf("%d*%d=%d",x,y,z);
> }

Hmm. This is a bit dodgy.

> now, when i try to compile this i get the ": python.h : no such file or
> directory"  error and it wont create the .o file i need to put in
> Setup.local to use it as a module.

Not really a Python problem. More a compiler related one. The solution
depend on what compiler you are using.

Assuming you are on Win32, and installed Python from the installer do:

cl -Ic:/progra~1/python/include -c resmodule.c		-> resmodule.obj

If you're on a Unix/Linux box:

cc -I/usr/local/include/python1.5 -c resmodule.c	-> resmodule.o

You'll also need to link with python15.lib/libpython1.5.a.

-----------------------------------------------------------------
Adrian Eyre <a.eyre at optichrome.com> - http://www.optichrome.com 





More information about the Python-list mailing list