开发者

Install script for C project with Python API

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 P开发者_如何学编程ython 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?


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


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜