13

I'm trying to install a Python module that contains C modules. The C code relies on a library being available in the system's global install locations (/usr/include, /usr/lib), but in my case I only have a local installation of this lib available. Therefore, I would like to pass parameters (e.g., --incdir, --libdir) when calling "setup.py build" so that these values end up in the setup script.

Is there a way to achieve this?

BjoernD
  • 4,720
  • 27
  • 32
  • 3
    This question is a duplicate of [How may I override the compiler (GCC) flags that setup.py uses by default?](https://stackoverflow.com/q/6928110/11725753) – EvgenKo423 Jul 13 '21 at 12:12
  • Related: [python pip specify a library directory and an include directory](https://stackoverflow.com/q/18783390/11725753). – EvgenKo423 Jul 13 '21 at 14:19

1 Answers1

15

I found out that prepending

CFLAGS="-I<local include dir>" LDFLAGS="-L<local lib dir>"

to the command line when calling setup.py did the trick.

BjoernD
  • 4,720
  • 27
  • 32
  • 1
    python setup.py build_ext --include-dirs=/path/to/include/ --library-dirs=/path/to/libs/ --libraries=mylib --rpath=$ORIGIN works, type `python setup.py build_ext --help`, or add them to setup.py `Extension`, see [Distutil API Reference](https://docs.python.org/2/distutils/apiref.html#distutils.core.Extension). Put them in [setup.cfg](https://docs.python.org/2/distutils/configfile.html?highlight=setup%20configuration), also see [Install Python Modules](https://docs.python.org/2/install/#distutils-configuration-files). No idea what the section on "Tweaking compiler/linker flags is talking about. – Mark Mikofski Nov 21 '14 at 23:18
  • 1
    See also [Distutils compiler options configuration](http://stackoverflow.com/a/16078447/1020470) and [How to pass flag to gcc in Python setup.py script?](http://stackoverflow.com/a/1676413/1020470). – Mark Mikofski Nov 21 '14 at 23:22
  • 3
    Notably this does not work on Windows/MSVC, as the CFLAGS are totally ignored there, as are all the other options in `distutils.sysconfig.customize_compiler()` – schlenk Jun 29 '16 at 09:54