Page 1 of 1

Cython compilation error

Posted: 26 Apr 2019, 08:24
by Qottmann
Hello,
does somebody have an idea what might be the problem here? I tried to compile the cython files but get this error message. I updated cython but the problem remains:

Code: Select all

:~/TeNPy$ bash ./compile.sh
Compiling tenpy/linalg/_npc_helper.pyx because it changed.
[1/1] Cythonizing tenpy/linalg/_npc_helper.pyx
/home/kkottmann/TeNPy/tenpy/tools/optimization.py:276: UserWarning: Couldn't load compiled cython code. Code will run a bit slower.
  warnings.warn("Couldn't load compiled cython code. Code will run a bit slower.")
running build_ext
building 'tenpy.linalg._npc_helper' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/tenpy
creating build/temp.linux-x86_64-3.6/tenpy/linalg
gcc -pthread -B /export/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/export/anaconda3/lib/python3.6/site-packages/numpy/core/include -I/export/anaconda3/include/python3.6m -c tenpy/linalg/_npc_helper.cpp -o build/temp.linux-x86_64-3.6/tenpy/linalg/_npc_helper.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
In file included from /export/anaconda3/lib/python3.6/site-packages/numpy/core/include/numpy/ndarraytypes.h:1811:0,
                 from /export/anaconda3/lib/python3.6/site-packages/numpy/core/include/numpy/ndarrayobject.h:18,
                 from /export/anaconda3/lib/python3.6/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from tenpy/linalg/_npc_helper.cpp:627:
/export/anaconda3/lib/python3.6/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/tenpy
creating build/lib.linux-x86_64-3.6/tenpy/linalg
g++ -pthread -shared -B /export/anaconda3/compiler_compat -L/export/anaconda3/lib -Wl,-rpath=/export/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/tenpy/linalg/_npc_helper.o -o build/lib.linux-x86_64-3.6/tenpy/linalg/_npc_helper.cpython-36m-x86_64-linux-gnu.so
/export/anaconda3/compiler_compat/ld: cannot find -lm
collect2: error: ld returned 1 exit status
error: command 'g++' failed with exit status 1
Thanks in advance!
Best regards,
Korbinian

Re: Cython compilation error

Posted: 29 Apr 2019, 09:27
by Johannes
This looks like a linking error. What OS are you using?
Can you compile the first minimal example from http://docs.cython.org/en/latest/src/qu ... build.html?

Another minimal example with numpy: save this code as "a.pyx".

Code: Select all

cimport numpy as cnp
import numpy as np
cnp.import_array()

def my_sum(cnp.ndarray[cnp.intp_t, ndim=1] values):
    cdef s = 0
    for i in range(values.shape[0]):
        s += values[i]
    return s

def main():
    print("Hello world")
    v = np.arange(20, dtype=np.intp)
    print(my_sum(v))
Can you then do the following in the terminal?

Code: Select all

cythonize -bi a.pyx
python -c 'import a; a.main()'

Re: Cython compilation error

Posted: 29 Apr 2019, 12:24
by Qottmann
Hello Johannes, thanks again for the answer!

On my personal computer on Ubuntu 18 it works fine, the problem here is on a Ubuntu 16 server. When I try to compile your minimal example I get a similar error:

Code: Select all

(tenpy) kkottmann@pcl1016:~$ cythonize -bi a.pyx
Compiling /home/kkottmann/a.pyx because it changed.
[1/1] Cythonizing /home/kkottmann/a.pyx
/home/kkottmann/.conda/envs/tenpy/lib/python3.7/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/kkottmann/a.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'a' extension
creating /home/kkottmann/tmpceb6ljwl/home
creating /home/kkottmann/tmpceb6ljwl/home/kkottmann
gcc -pthread -B /home/kkottmann/.conda/envs/tenpy/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/kkottmann/.conda/envs/tenpy/include/python3.7m -c /home/kkottmann/a.c -o /home/kkottmann/tmpceb6ljwl/home/kkottmann/a.o
In file included from /usr/include/numpy/ndarraytypes.h:1777:0,
                 from /usr/include/numpy/ndarrayobject.h:18,
                 from /usr/include/numpy/arrayobject.h:4,
                 from /home/kkottmann/a.c:606:
/usr/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
gcc -pthread -shared -B /home/kkottmann/.conda/envs/tenpy/compiler_compat -L/home/kkottmann/.conda/envs/tenpy/lib -Wl,-rpath=/home/kkottmann/.conda/envs/tenpy/lib -Wl,--no-as-needed -Wl,--sysroot=/ /home/kkottmann/tmpceb6ljwl/home/kkottmann/a.o -o /home/kkottmann/a.cpython-37m-x86_64-linux-gnu.so
/home/kkottmann/.conda/envs/tenpy/compiler_compat/ld: cannot find -lpthread
/home/kkottmann/.conda/envs/tenpy/compiler_compat/ld: cannot find -lc
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
Maybe if it helps here is the config output:

Code: Select all

tenpy.show_config()
tenpy 0.4.0.dev0+8f0448a (not compiled),
git revision 8f0448a4247c45c29eab15b59bb10fd70c67732a using
python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 09:07:38) 
[GCC 7.3.0]
numpy 1.13.3, scipy 1.1.0
I used the predefined conda environment that is on the github from you. Compared to the installation instructions I have Python 3.6.7 (instead of 3.7.3) and numpy and scipy are older versions (even though when I try conda install numpy scipy it tells me I am up to date). I dont know if those small deviations could be responsible for it or not.

Re: Cython compilation error

Posted: 29 Apr 2019, 13:54
by Johannes
Did you do the sudo apt-get install build-essential?
Or in other words, do you have a working C++ compiler?

Re: Cython compilation error

Posted: 29 Apr 2019, 15:03
by Qottmann
I did not specifically install this compiler, no.

I asked our admin to check if gcc is up to date (which it was) but he also updated a bunch of other things and now it is working. I dont know what exactly was the problem (so for future references this thread might be not very helpful) but at least it is running now.

Re: Cython compilation error

Posted: 29 Apr 2019, 16:14
by Johannes
Qottmann wrote: 29 Apr 2019, 15:03 ... but at least it is running now.
Glad to hear that :D