Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython compilation appends text to filename, how to get rid of it?

I'm working with cython on the Ubuntu platform. Everything works fine, except there is one thing that annoys me. When compiling a cython project to a .so file, the filename of the .pyx file is appended with "cpython-36m-x86_64-linux-gnu". For example, if I build "helloworld.pyx" the resulting .so file is called: "helloworld.cpython-36m-x86_64-linux-gnu.so". I however would just want it to be called "helloworld.so".

I thought the answer would be quite trivial, so I started googling, even after 30 minutes I could find nothing on the subject. Does anyone have any idea?

Here is my .pyx file:

print('hello world')

setup.py file:

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloworld.pyx")
)

building the file:

python setup.py build_ext --inplace
Compiling helloworld.pyx because it changed.
[1/1] Cythonizing helloworld.pyx
running build_ext
building 'helloworld' extension
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/**/anaconda3/include/python3.6m -c helloworld.c -o build/temp.linux-x86_64-3.6/helloworld.o
gcc -pthread -shared -L/home/**/anaconda3/lib -Wl,-rpath=/home/ed/anaconda3/lib,--no-as-needed build/temp.linux-x86_64-3.6/helloworld.o -L/home/**/anaconda3/lib -lpython3.6m -o /home/**/new_project/helloworld.cpython-36m-x86_64-linux-gnu.so
like image 576
Anonthecanon Avatar asked Mar 15 '17 17:03

Anonthecanon


1 Answers

You cannot get rid of it, at least not automatically. PEP 3149 defines the tags to include in the file name of compiled modules: https://www.python.org/dev/peps/pep-3149/

The tag includes the Python implementation (here cpython), version (here 36 for 3.6), a flag for the compile-time options (m for using Python's memory allocator, this is by default). The platform tag x86_64-linux-gnu is not part of PEP 3149, I don't know where it is defined.

These changes are implemented in distutils and cython is not "to blame" :-)

The import name of the package is not affected by this file name.

Do you have any specific reason for not adhering to PEP 3149? You can replace the build process of the setup file by issuing manually the linker command, but this is less convenient.

like image 172
Pierre de Buyl Avatar answered Sep 19 '22 04:09

Pierre de Buyl