setup.py没有安装数据文件 [英] setup.py not installing data files
问题描述
我有一个Python库,除了常规的Python模块外,还有一些数据文件需要放在/usr/local/lib/python2.7/dist-package/mylibrary中。
I have a Python library that, in addition to regular Python modules, has some data files that need to go in /usr/local/lib/python2.7/dist-package/mylibrary.
不幸的是,我无法说服setup.py在此处实际安装数据文件。请注意,此行为是在安装过程中-而不是sdist。
Unfortunately, I have been unable to convince setup.py to actually install the data files there. Note that this behaviour is under install - not sdist.
此处是setup.py的稍作修改的版本。py
Here is a slightly redacted version of setup.py
module_list = list_of_files
setup(name ='Modules',
version ='1.33.7',
description ='My Sweet Module',
author ='PN',
author_email ='email',
url ='url',
packages = ['my_module'],
# I tried this. It got installed in /usr/my_module. Not ok.
# data_files = [ ("my_module", ["my_module/data1",
# "my_module/data2"])]
# This doesn't install it at all.
package_data = {"my_module" : ["my_module/data1",
"my_module/data2"] }
)
这是Python 2.7(必须在2.6中运行最终),并且必须在10.04和12+之间的某些Ubuntu上运行。立即在12.04上进行开发。
This is in Python 2.7 (will have to run in 2.6 eventually), and will have to run on some Ubuntu between 10.04 and 12+. Developing it right now on 12.04.
推荐答案
http://docs.python.org/distutils/setupscript.html#installing-additional-files
如果目录是相对路径,则相对于
安装前缀(纯Python软件包的Python sys.prefix,
sys.exec_prefix用于包含扩展模块的软件包。)
If directory is a relative path, it is interpreted relative to the installation prefix (Python’s sys.prefix for pure-Python packages, sys.exec_prefix for packages that contain extension modules).
这可能会做到:
data_files = [ ("my_module", ["local/lib/python2.7/dist-package/my_module/data1",
"local/lib/python2.7/dist-package/my_module/data2"])]
或者只使用连接以添加前缀:
Or just use join to add the prefix:
data_dir = os.path.join(sys.prefix, "local/lib/python2.7/dist-package/my_module")
data_files = [ ("my_module", [os.path.join(data_dir, "data1"),
os.path.join(data_dir, "data2")])]
这篇关于setup.py没有安装数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!