setup.py build中的data_files文件夹(setuptools)

时间:2016-04-25 13:13:22

标签: python setuptools setup.py

我正在尝试将data_file添加到setup.py项目中。我可以使用/tmp/目录中的文件,不能在脚本的当前目录中使用它:

from setuptools import setup, find_packages
import os

packages = find_packages("src")
foo_path = os.path.dirname(os.path.abspath(__file__)) + '/foo.dat'
print foo_path   # file exists and there full absolute path is printed:
                 # '/home/loom/myapp/foo.dat'

setup(name='myapp',
        version='0.2.0',
        url='http://loom.st',
        author='Loom',
        author_email='admin@loom.st',
        package_dir={'': 'src'},
        packages=packages,
        py_modules=['my_start'],
# 1.        data_files=[('lib/python', [foo_path])],
# 2.        data_files=[('lib/python', [/tmp/foo.dat])],
        setup_cfg=True,
        )

当行1.取消注释时,python setup.py bdist_rpm失败并显示消息:

running install_data
error: can't copy '/home/loom/myapp/build/bdist.linux-x86_64/rpm/BUILD/myapp-0.2.0/foo.dat': doesn't exist or not a regular file
error: Bad exit status from /var/tmp/rpm-tmp.02mmV8 (%install)

取消注释第2.行后,即可完成构建,并包含foo.dat(文件/tmp/foo.dat存在)

为什么行1.会导致错误以及如何避免错误?

1 个答案:

答案 0 :(得分:1)

这里的问题是,您给出了<UserControl ...><Image DataContext="{Binding}" DataContextChanged="ItemImage_DataContextChanged" /></UserControl> 的错误路径,它是作为目录提供的:

  

/home/loom/myapp/foo.dat /

只需删除末尾的foo.dat,因此它是文件的路径:

  

/home/loom/myapp/foo.dat

如果文件确实存在,现在一切都应该没问题。