Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
759 views
in Technique[技术] by (71.8m points)

python - why Cython compiler generates a so with suffix 'cpython-35m-x86_64-linux-gnu.so'

#setup.py    
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext}, 
    ext_modules = [Extension("module_name", ["xxxx.pyx", './yyyyy.c'],
                    language='c',
                    extra_compile_args = ['-std=gnu11'],
                    extra_link_args=['-std=gnu11']                 
                    )]
)


$ python --version
Python 3.5.1
$ python -c "import cython; print(cython.__version__);"
0.25.2
$ python setup.py build_ext -i

Question> Why Cython generates the module name as module_name.cpython-35m-x86_64-linux-gnu.so instead of module_name.so?

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A full description is available in PEP 3149. In short: this is a change that applies from Python 3.2 onwards. A version identifier is deliberately added to the filename; filenames with this version identifier are used in preference to those without (but a plain .so or .pyd file without the version identifier will be used if no other option is available to import).

There are two main advantages to adding information to the .so or .pyd file about what version of Python it was compiled against:

  1. It is possible to have .so/.pyd files compatible with multiple versions of Python all compiled to the same directory, making it easier to use or distribute libraries for multiple versions of Python.
  2. It protects you from accidentally importing a module compiled for the wrong version of Python. This is a good thing, since the ABI isn't 100% compatible between Python versions (but is likely to be mostly compatible, which will give you occasional and confusing bugs)

The change to the file name affects all compiled Python modules, not just Cython.

This question describes how to change the identifier that's added - there is rarely a good reason for doing so, however.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...