使用python模块分发预构建的库 [英] Distributing pre-built libraries with python modules

查看:72
本文介绍了使用python模块分发预构建的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下脚本分发包含纯python代码的模块。

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'},
       )



<我遇到的问题是,我修改了一个使用外部库的文件(.so文件),我需要将其与现有模块一起提供。建议我使用package_data包含库。我将脚本修改为以下内容。

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']},
       )

问题是,添加package_data并没有什么区别。这不是在任何位置(站点软件包或站点软件包/ mtester中都没有安装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).

系统信息:Fedora 10、64位, python 2.5(是的,它很古老。但这是我们的构建机器,它需要保持这种方式以保持向后兼容性)

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!

推荐答案

不幸的是, package_data 查找相对于文件的文件。包装的顶部。一种解决方法是将帮助程序库与其余代码一起移到模块目录下:

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/

然后相应地修改 package_data 参数:

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

然后测试:

% 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

这篇关于使用python模块分发预构建的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆