Reputation: 6723
I have a Cython code that runs and works fine under WinPython but giving me issues when I switch from WinPython to Anaconda3. I am using Python 3.4
The test code is :
# cython: boundscheck=False
# cython: wraparound=False
# cython: cdivision=True
cimport cython
cimport numpy as np
import numpy as np
from numpy cimport ndarray as ar
from libc.math cimport *
cpdef ar[double, ndim=1, mode='c'] test(ar[double, ndim=1, mode='c'] x):
cdef:
int n = x.shape[0]
Py_ssize_t i
ar[double, ndim=1, mode='c'] y = np.zeros(n)*np.nan
with nogil:
for i in range(0, n):
y[i] = x[i]+1
return y
The compilation code is:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy as np
ext_modules = [Extension('test', ['tech/test.pyx'], include_dirs=[np.get_include()],
define_macros=[('NPY_NO_DEPRECATED_API', None)],
extra_compile_args=['-O3', '-march=native', '-ffast-math'],
libraries=['m']
)]
setup(
name="Test Function",
cmdclass={'build_ext': build_ext},
ext_modules=ext_modules
)
I am using MinGw to compile, so under the ...\Anaconda3\Lib\distutils
folder I have a file that has
[build]
compiler = mingw32
In addition in the PATH environment variables, I have:
default: ...\Anaconda3 ...\Anaconda3\Scripts
also added: ...\Anaconda3\libs (this contains python34)
also added: mingw32 files copied from WinPython that contain gcc
etc:
...\Anaconda3\Tools\tools\mingw32\bin (this contains gcc)
...\Anaconda3\Tools\tools\mingw32\x86_64-w64-mingw32\bin
when I try:
python setup.py build_ext --inplace
the code runs fine until the test.c
, test.o
and test.def
have been generated. thereafter this is what I get:
C:\Anaconda3\Tools\tools\mingw32\bin\gcc.exe -shared -s build\temp.win-amd64-3.4\Release\tech\test.o build\temp.win-amd64-3.4\Release\tech\test.def -LC:\Anaconda3\libs -LC:\Anaconda3\PCbuild\amd64 -lm -lpython34 -lmsvcr100 -
o P:\Documents\Temp\python-master\python-master\common\test.pyd
build\temp.win-amd64-3.4\Release\tech\test.o:test.c:(.text+0x8e): undefined reference to `__imp_PyExc_TypeError'
build\temp.win-amd64-3.4\Release\tech\test.o:test.c:(.text+0x10e): undefined reference to `__imp_PyExc_ValueError'
build\temp.win-amd64-3.4\Release\tech\test.o:test.c:(.text+0x259): undefined reference to `__imp__PyThreadState_Current'
....
....
C:/Anaconda3/Tools/tools/mingw32/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw3 ild\temp.win-amd64-3.4\Release\tech\test.o: bad reloc address 0x0 in section `.data'
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\Anaconda3\\Tools\\tools\\mingw32\\bin\\gcc.exe' failed with exit status 1
First of all, I couldn't find a Anacond3\PCBuild\amd64
directory/file anywhere.
I tried to look all over the internet, but I couldn't find any reference to __imp_PyExc_TypeError
, __imp__PyThreadState_Current
, __imp_PyExc_ValueError
.
What could be going wrong with the final conversion to *.pyd
file?
Upvotes: 2
Views: 373
Reputation: 91630
You can run
conda remove libpython
to make Anaconda use Visual Studio instead of mingw, which may work better.
Upvotes: 1
Reputation: 1191
I suspect Anaconda doesn't support mingw-64 yet.
Historically mingw-64 was indeed a hopeless idea until Cark Kleffner came with his static version.
Things may (should ?) change when Carl's updated version will be available as mingwpy wheel.
Upvotes: 1