python应用程序打包如何使用MANIFEST.in打包非py的静态资源

1、在setup.py中设置include_package_data=True

格式参照:

from setuptools import setup, find_packages

setup(
    name='your_project_name',
    version='0.1',
    description='A description.',
    packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
    include_package_data=True,
    install_requires=[],
)

2、在根目录下新建 MANIFEST.in

MANIFEST.in的内容:

include *.txt  #包含根目录下的所有txt文件
recursive-include examples *.txt *.py  #包含所有位置的examples文件夹下的txt与py文件
prune examples/sample?/build  #排除所有位置examples/sample?/build

意为:

The meanings should be fairly clear: include all files in the distribution root matching .txt, all files anywhere under the examples directory matching .txt or *.py, and exclude all directories matching examples/sample?/build.

以及包含安装包下的所有文件:

global-include * 

其他书写方式:

include pat1 pat2 ...   #include all files matching any of the listed patterns
exclude pat1 pat2 ...   #exclude all files matching any of the listed patterns
recursive-include dir pat1 pat2 ...  #include all files under dir matching any of the listed patterns
recursive-exclude dir pat1 pat2 ... #exclude all files under dir matching any of the listed patterns
global-include pat1 pat2 ...    #include all files anywhere in the source tree matching — & any of the listed patterns
global-exclude pat1 pat2 ...    #exclude all files anywhere in the source tree matching — & any of the listed patterns
prune dir   #exclude all files under dir
graft dir   #include all files under dir

你可能感兴趣的:(python)