I have files in the following directory structure:
dir1
| setup.py
| dir2
| dir3
| myFile.py
| myOtherFile.py
I want to build myFile.so
and myOtherFile.so
using cythonize
and maintain this directory structure.
If I use this script:
# setup.py
from setuptools import Extension, setup
from Cython.Build import cythonize
import os
extensions=[Extension('dir2.dir3.*', ['dir2/dir3/*.py']]
setup(
name="my_file",
ext_modules=cythonize(extensions, language_level=3)
)
and run it with python setup.py build_ext --inplace
, myFile.c
and myOtherFile.c
are built in dir2/dir3
next to the corresponding .py
files, but myFile.so
and myOtherFile.so
are built in dir1
, the parent directory that contains setup.py
(actually, they appear to be copied there from the build
dir as the last step of setup.py
, which displays: >> running build_ext copying build/lib.linux-x86_64-3.7/myFile.cpython-37m-x86_64-linux-gnu.so ->
just before the script exits).
If I use the command line version cythonize -i -3 dir2/dir3/*.py
everything works as expected (i.e. the .so
files appear in dir2/dir3
). What do I need to add to my setup.py
file to get the same behavior?
Note: unlike this toy example, I actually have a number of files in dir2/dir3
, so I want to use the wild card *.py*
to identify the .py
files, rather than listing them individually.
question from:
https://stackoverflow.com/questions/65853419/how-to-build-so-files-in-place-using-python-setuptools-and-cythonize 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…