4

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

What is the best way to write installation/deployment scripts for a Linux/UNIX environment? Usually, I use the make utility to compile and install projects written in C. Most of the time, I just have the make utility compile all the source code into executables, and then copy the executables to /usr/local/bin.

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

But how can the appropriate directory for Python extension modules be detected by the Make utility? Is there an environment variable or something that lists the directories in Python's sys.path?

2
  • 3
    distutils can build extension modules, and should generally be your preferred way to install and deploy python modules. setup.py can most likely be run from your makefile if you're building the rest of the C library, or make can be called from your setup.py script. Commented Apr 19, 2011 at 16:28
  • 1
    To elaborate: check out this documentation to get you started. Commented Apr 19, 2011 at 18:56

2 Answers 2

1

If you cannot use python's distutils for some reason, you can try some heuristics in shell:

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

tested on:

  • RHEL5: /usr/lib64/python2.4/site-packages
  • Debian: /usr/local/lib/python2.6/dist-packages
  • Solaris: /usr/local/lib/python2.6/site-packages
Sign up to request clarification or add additional context in comments.

Comments

0

I would separate the project out into two parts. Your C part can use make as usual. Your python module can use the python setup tools, which are capable of building extensions.

(You can also write install targets, so you don't have to copy things manually)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.