Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change distutils' output directory?

When using python setup.py build with this code:

import setuptools
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize("module1.pyx", build_dir="temp"))

the .pyd library is produced in .\build\lib.win-amd64-2.7\module1.pyd.

How to make the output .pyd file to the current folder . instead?

Note: the cythonize parameter build_dir="temp" works: the module1.c file produced by cython is in temp\ indeed. My question is about the output .pyd file.

like image 649
Basj Avatar asked Feb 03 '23 21:02

Basj


2 Answers

Thanks to

python setup.py build --help 

I found that the solution is to use the parameter build-lib:

python setup.py build --build-lib=.

Then the .pyd files will be created in the same folder as the .pyx Cython files.


In the case you don't want to pass it as command-line argument, this is also possible:

setup(ext_modules=cythonize("module1.pyx", build_dir="build"), script_args=['build'], 
                                            options={'build':{'build_lib':'.'}})

Another alternative with inplace option of build_ext (it finally does the same):

setup(ext_modules=cythonize("module1.pyx", build_dir="build"), script_args=['build_ext'], 
                                            options={'build_ext':{'inplace':True}})
like image 181
Basj Avatar answered Feb 06 '23 11:02

Basj


Use the argument --dist-dir=[default: dist] option.

  --dist-dir (-d)   directory to put the source distribution archive(s) in
                    [default: dist]

Read more about packaging here.

You can use the following: python3 setup.py sdist --dist-dir=your-dir

like image 26
Julian Camilleri Avatar answered Feb 06 '23 11:02

Julian Camilleri