파이썬
python3.6 cython mingw32 windows사용법
헬로르르
2018. 9. 1. 15:19
python3.6 에서 mingw32 를 이용해서 cython 모듈 사용방법 입니다.
보통 msvc 를 이용해서 하는 예제만 있던데, gcc를 사용하시는분들은 아래처럼 하시면 됩니다.
test.pyx
1 2 3 4 5 6 7 8 9 10 11 | ''' cython test.py gcc -mdll -O -Wall -Ic:\Python36-32\include -c test.c gcc -shared -LC:\Python36-32\libs test.o -lpython36 -o test.pyd ''' def inverse(float x): cdef float y y = 1.0 / x return y | cs |
1. mingw32 설치
2. 환경변수 설정 ( C:\MinGW\bin )
3. python -m pip install cython
4. cython test.pyx
-> cython 컴파일 할 때, pyx 로만 인식 가능했습니다.
5. gcc -mdll -O -Wall -Ic:\Python36-32\include -c test.c
-> object file 생성
6. gcc -shared -LC:\Python36-32\libs test.o -lpython36 -o test.pyd
-> 생성된 object로 부터 python 모듈 생성
7. python> import test
8. python> test.inverse(100)