Building python modules is usually fairly easy. The usual build and install commands. Its really easy to build and install to standard paths, but if we have to install to a non-standard path, then we have to build it differently.

The most ghetto way to fix this is by hacking the script by hand:


This will force distutils to pick up custom include and library directories. There is ofcourse a cleaner way to do this.

Just like ./configure, there is a way to configure in python too:

python config --include-dirs=<custom include path> --library-dirs=<custom library path>
python build

While this should build fine on most Linux machines, it might still not build properly on OSX X 10.8 or later:

ld: library not found for -lxyz
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1

To solve this to cleanly configure and build a module, we have to create a setup.cfg file with options for various commands:


For some reason, config does not do what it is supposed to do. Secondly, the 'build' command does not have the library_dirs and include_dirs options. So the next best way is to use the alternate build commands like 'build_ext'. Once you have the setup.cfg file in place, you can do the usual and it should work.

python build_ext


  • Create a setup.cfg with options for the build_ext command
  • Then run the with build_ext