This is 2 separate errors in single question.
I followed the docs on Cython website on how to build a cython script. I Created .pyx file, did cython -a filename.pyx --embed
to create .c file and then
import pyximport; pyximport.install()
import filename
to run my simple hello world program.
Now I want to implement cython on Random Forest and I use the following modules while importing :
from __future__ import division
from sklearn.ensemble import RandomForestClassifier
import pymysql
import datetime
import csv
from operator import itemgetter
from sklearn.metrics import *
from algoScore import algo_score
import sys
When I try to do cython -a randomforest.pyx ** is showed some errors regarding **numpy so I thought since numpy used c headers, I need to build using distutils by providing include_path in setup.py (Following this link) and the following is my setup.py :
from distutils.core import setup
from Cython.Build import cythonize
import numpy
setup(
name = "Test script",
ext_modules = cythonize('randomforest.pyx', include_path = [numpy.get_include()]), # accepts a glob pattern
)
when I try building the file from command line by following command :
python setup.py build_ext --inplace
I get following errors :
running build_ext
building 'randomforest' extension
c:\mingw\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c randomforest.c -o build\temp.win32-2.7\Release\randomforest.o
writing build\temp.win32-2.7\Release\randomforest.def
c:\mingw\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\randomforest.o build\temp.win32-2.7\Release\randomforest.def -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27 -lmsvcr90 -o "e:\PA - Project\CodeBase\Tests\balanceClasses\balanceClasses\RF\randomforest.pyd"
C:\Python27\libs/libpython27.a(dmmes00976.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a'
C:\Python27\libs/libpython27.a(dmmes00239.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a'
C:\Python27\libs/libpython27.a(dmmes00236.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a'
C:\Python27\libs/libpython27.a(dmmes00245.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a'
C:\Python27\libs/libpython27.a(dmmes00343.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a'
C:\Python27\libs/libpython27.a(dmmes00386.o):(.idata$7+0x0): more undefined references to `_head_C__build27_cpython_PCBuild_libpython27_a' follow
collect2: ld returned 1 exit status
error: command 'c:\\mingw\\bin\\gcc.exe' failed with exit status 1
Also, though error are generated, I do get a .c file generated and .def & .o files as well.
I want to know weather the file is compiler? Can I run it from pyximport by importing or not? And also, if I can't then is there any specific way to compile the .c file using any compiler into standalone .exe?
I tried using VC++ command line by compiler /c and I had faced the issue as described in following link (Edit 1).
Would be grateful if someone an help me as I've been facing this since long and even googling doesn't seem to give any answer.