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
348 views
in Technique[技术] by (71.8m points)

How to build .so files in place using python setuptools and cythonize

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

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

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

...