Cython build through setup.py does the wrong thing (putting all .so files in an additional src dir)

I am trying to convert using pyximport to creation through distutils, and I am obscured by strange variations of its creation where you can put .so files. So, I decided to build a tutorial from a cython document, only to find it, print a message about its building, but do not. I am in virtualenv and it all has cython, python2.7 installed, etc.

First basics:

$ cython --version Cython version 0.21.2 $ cat setup.py from distutils.core import setup from Cython.Build import cythonize print "hello build" setup( ext_modules = cythonize("helloworld.pyx") ) $ cat helloworld.pyx print "hello world" 

Now when I create it, everything looks fine, except for the extra src / src files in the output:

 $ python setup.py build_ext --inplace hello build Compiling helloworld.pyx because it changed. Cythonizing helloworld.pyx running build_ext building 'src.helloworld' extension x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c helloworld.c -o build/temp.linux-x86_64-2.7/helloworld.o creating /home/henry/Projects/eyeserver/dserver/src/src x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/helloworld.o -o /home/henry/Projects/eyeserver/dserver/src/src/helloworld.so 

And when I run it, it certainly fails:

 $ echo "import helloworld" | python Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named helloworld 

Until I translate the .so file from its additional src directory:

 $ mv src/helloworld.so . $ echo "import helloworld" | python Hello world 

What am I doing wrong? Obviously, I could make the build process move all .so files, but that seems really hacked.

+6
source share
1 answer

Whenever I use cython, I use the Extension command.

I will write the setup.py file as follows:

 from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize extensions = [ Extension("helloworld", ["helloworld.pyx"]) ] setup( ext_modules = cythonize(extensions) ) 

We hope that then it will be a .so file in the current directory.

+5
source

Source: https://habr.com/ru/post/980705/


All Articles