Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distributing pre-built libraries with python modules

I use the following script to distribute a module containing pure python code.

from distutils.core import setup, Extension
import os
setup (name = 'mtester',
       version = '0.1',
       description = 'Python wrapper for libmtester',
       packages=['mtester'],
       package_dir={'mtester':'module'},
       )

The problem I have is, I modified one of the files that uses an external library (a .so file), which I need to ship along with the existing module. I was suggested to use package_data to include the library. I modified the script to the following.

from distutils.core import setup, Extension
import os
data_dir = os.path.abspath('../lib64/')
setup (name = 'mtester',
       version = '0.1',
       description = 'Python wrapper for libmtester',
       packages=['mtester'],
       package_dir={'mtester':'module'},
       package_data={'mtester':[data_dir+'mhelper.so']},
       )

The problem is, adding package_data did not make any difference. This is not installing the mhelper.so in any location (neither in site-packages nor in site-packages/mtester).

System info: Fedora 10, 64 bit, python 2.5 (Yes it is ancient. But it is our build machine, and it needs to stay that way to maintain backward compatibility)

Any suggestions that would help me resolve this would be well appreciated!

like image 474
Pavan Yalamanchili Avatar asked Nov 05 '22 21:11

Pavan Yalamanchili


1 Answers

Unfortunately package_data looks for files relative to the top of the package. One fix is to move the helper library under the module dir with the rest of the code:

% mv lib64/mhelper.so module/

Then modify the package_data argument accordingly:

package_data = {'mtester': ['mhelper.so']}
...

Then test:

% python setup.py bdist
% tar tf dist/mtester-0.1.linux-x86_64.tar.gz | grep mhelper
./usr/local/lib/python2.5/dist-packages/mtester/mhelper.so
like image 172
samplebias Avatar answered Nov 13 '22 16:11

samplebias