Reputation: 149
I'm on an older computer and i'm attempting to use Cython to speed up some python code I wrote, however I cannot get Cython to work with even the simplest of scripts.
Here is the python code i am attempting to run through Cython, and from my knowledge should work:
def hw():
print "Hello World"
if __name__ == "__main__":
hw()
And here is the output from my terminal:
C:\PyProjects\_cython>python hw.py
Hello World
C:\PyProjects\_cython>cython hw.py
C:\PyProjects\_cython>gcc hw.c
In file included from hw.c:4:
Python.h:8:22: error: pyconfig.h: No such file or directory
hw.c:457: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx_
PyInt_AsUnsignedLongLong'
hw.c:461: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx_
PyInt_AsLongLong'
hw.c:465: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx_
PyInt_AsSignedLongLong'
hw.c: In function '__Pyx_PyUnicode_Equals':
hw.c:826: error: 'Py_UNICODE' undeclared (first use in this function)
hw.c:826: error: (Each undeclared identifier is reported only once
hw.c:826: error: for each function it appears in.)
hw.c:826: error: expected ';' before 'ch1'
hw.c:827: error: expected ';' before 'ch2'
hw.c:828: error: 'ch1' undeclared (first use in this function)
hw.c:828: error: 'ch2' undeclared (first use in this function)
hw.c: At top level:
hw.c:1204: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx
_PyInt_AsUnsignedLongLong'
hw.c:1274: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx
_PyInt_AsLongLong'
hw.c:1344: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx
_PyInt_AsSignedLongLong'
hw.c: In function '__Pyx_InitStrings':
hw.c:1564: warning: assignment makes pointer from integer without a cast
hw.c: In function '__Pyx_PyInt_AsSize_t':
hw.c:1669: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'val'
hw.c:1669: error: 'val' undeclared (first use in this function)
hw.c:1670: error: expected ')' before 'LONG_LONG'
hw.c:1672: error: expected ')' before 'LONG_LONG'
I am on windows 7 64bit using 32bit python 2.7
Upvotes: 1
Views: 5107
Reputation: 310257
Have a look at the documentation. In my experience, the easiest way to do this is using distutils
as it knows all the information necessary to pass along to the compiler (e.g. location of headers, important libraries, compiler options to create a suitable shared object, etc) And, after all, writing a setup.py
file isn't terribly difficult. If you don't want to install the library, just do python setup.py build
and copy the shared object into whatever directory you want (although you might need to dig a little in the build
directory in order to find it).
Upvotes: 3