Install script for C project with Python API

I have a project that is mostly written in C, but it also has a Python API that uses Python extension modules written in C.

What is the best way to write installation / deployment scripts for a Linux / UNIX environment? I usually use the make utility to compile and install projects written in C. In most cases, I have a make utility that compiles all the source code into executable files and then copies the executable files to /usr/local/bin .

However, my Python API requires compiling / installing shared library ( .so ) files for use with Python. This is mainly related to compiling the necessary C files, and then copying the shared libraries to some directory that is part of Python sys.path , for example /usr/local/lib/pythonX.X/dist-packages/ .

But how can you determine the appropriate directory for Python extension modules using the Make utility? Is there an environment variable or something that lists directories in Python sys.path ?

+4
source share
2 answers

If you cannot use python distutils for any reason, you can try several heuristics in the shell:

 INSTALL_PATH=$(python -c 'import sys; print [ i for i in sys.path if i.endswith("-packages") ][0]') 

tested for:

  • RHEL5: /usr/lib64/python2.4/site-packages
  • Debian: /usr/local/lib/python2.6/dist-packages
  • Solaris: /usr/local/lib/python2.6/site-packages
+1
source

I would divide the project into two parts. Your C part can use make as usual. Your python module can use python customization tools that can create extensions.

(You can also write installation goals, so you don’t need to copy things manually)

0
source

All Articles