[Cython] distutils setup.py
bonjour,
je me creuse la tête pour faire fonctionner un exemple de Cython:
http://docs.cython.org/docs/sharing_...xtension-types
Voici comment est architecturé mon répertoire:
Code:
1 2 3 4 5 6
| setup.py
test
__init__.py
Shrubbing.pxd
Shrubbing.pyx
Landscaping.pyx |
voici le contenu des fichiers:
setup.py:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
#---------------------------------------------------------------------------------------------------
# Installation instructions
#---------------------------------------------------------------------------------------------------
"""
python setup.py build_ext --inplace
python setup.py install
"""
#---------------------------------------------------------------------------------------------------
# Cython extensions
#---------------------------------------------------------------------------------------------------
sources = []
sources.append("test/Shrubbing.pyx")
sources.append("test/Landscaping.pyx")
ext_modules = [Extension("test.test", sources)]
#---------------------------------------------------------------------------------------------------
# Setup
#---------------------------------------------------------------------------------------------------
setup(packages = ["test"],
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
) |
Shrubbing.pxd:
Code:
1 2 3
| cdef class Shrubbery:
cdef int width
cdef int length |
Shrubbing.pyx:
Code:
1 2 3 4 5 6 7
| cdef class Shrubbery:
def __new__(self, int w, int l):
self.width = w
self.length = l
def standard_shrubbery():
return Shrubbery(3, 7) |
Landscaping.pyx:
Code:
1 2 3 4 5 6
| cimport Shrubbing
import Shrubbing
cdef Shrubbing.Shrubbery sh
sh = Shrubbing.standard_shrubbery()
print "Shrubbery size is %d x %d" % (sh.width, sh.height) |
J'aimerais pouvoir distribuer ce module en utilisant distutils mais je n'arrive pas à configurer le setup.py pour qu'il me génère la librairie (.sl sur ma plateforme).
J'arrive à le faire fonctionner lorsque tout est dans un seul fichier Cython (éventuellement avec un pxd) mais je n'y arrive pas quand le code est partagé sur plusieurs .pyx.
Voici le message d'erreur à la compilation:
Code:
1 2 3 4
| ld: Duplicate symbol "__pyx_module_is_main_test__test" in files build/temp.hp-ux-B.11.11-9000/785-2.4/test/Shrubbing.o and build/temp.hp-ux-B.11.11-9000/785-2.4/test/Landscaping.o
ld: Duplicate symbol "inittest" in files build/temp.hp-ux-B.11.11-9000/785-2.4/test/Shrubbing.o and build/temp.hp-ux-B.11.11-9000/785-2.4/test/Landscaping.o
2 errors.
error: command '/bin/ld' failed with exit status 1 |
Et la doc sur Cython sur la dictribution de fichiers multiples est... comment dire... insuffisante :aie:
http://docs.cython.org/docs/source_f...s-in-a-package
Si des gens se sont cassés les dents sur Cython, je suis preneur de toute info :)
Merci d'avance !