如何将静态文件包含到setuptools – python包中

包含静态文件是不可能的! 我尝试了在教程和文档中find的所有东西,但都是徒劳的…

我想包括./static/data.txt,有我的代码:

# setup.py import os,glob from setuptools import setup,find_packages setup( name = "PotatoProject", version = "0.1.1", author = "Master Splinter", author_email = "splinter@initech.com", description = ("The potatoproject!"), url = 'http://www.google.com', license = "BSD", # adding packages packages=find_packages('src'), package_dir = {'':'src'}, # trying to add files... include_package_data = True, package_data = { '': ['*.txt'], '': ['static/*.txt'], 'static': ['*.txt'], }, scripts=['src/startPotato'], classifiers=[ "Development Status :: 3 - Alpha", "Topic :: Utilities", "License :: OSI Approved :: BSD License", ], ) 

文件系统:

 . ├── setup.py └── src ├── distutils_setup.py ├── Potato │  ├── __init__.py │  ├── potatoData.txt │  └── printer.py ├── startPotato ├── static │  └── data.txt └── Tomato ├── big.py └── __init__.py 

运行时输出: $ python setup.py sdist

 running sdist running egg_info creating src/PotatoProject.egg-info writing src/PotatoProject.egg-info/PKG-INFO writing top-level names to src/PotatoProject.egg-info/top_level.txt writing dependency_links to src/PotatoProject.egg-info/dependency_links.txt writing manifest file 'src/PotatoProject.egg-info/SOURCES.txt' reading manifest file 'src/PotatoProject.egg-info/SOURCES.txt' writing manifest file 'src/PotatoProject.egg-info/SOURCES.txt' warning: sdist: standard file not found: should have one of README, README.txt creating PotatoProject-0.1.1 creating PotatoProject-0.1.1/src creating PotatoProject-0.1.1/src/Potato creating PotatoProject-0.1.1/src/PotatoProject.egg-info creating PotatoProject-0.1.1/src/Tomato making hard links in PotatoProject-0.1.1... hard linking setup.py -> PotatoProject-0.1.1 hard linking src/startPotato -> PotatoProject-0.1.1/src hard linking src/Potato/__init__.py -> PotatoProject-0.1.1/src/Potato hard linking src/Potato/printer.py -> PotatoProject-0.1.1/src/Potato hard linking src/PotatoProject.egg-info/PKG-INFO -> PotatoProject-0.1.1/src/PotatoProject.egg-info hard linking src/PotatoProject.egg-info/SOURCES.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info hard linking src/PotatoProject.egg-info/dependency_links.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info hard linking src/PotatoProject.egg-info/top_level.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info hard linking src/Tomato/__init__.py -> PotatoProject-0.1.1/src/Tomato hard linking src/Tomato/big.py -> PotatoProject-0.1.1/src/Tomato Writing PotatoProject-0.1.1/setup.cfg creating dist Creating tar archive removing 'PotatoProject-0.1.1' (and everything under it) 

并没有添加txt! 没有static / data.txt也没有Potato / potatoData.txt …

我错过了什么? 谢谢!

刚刚在setup.py的同一目录中添加了一个MANIFEST.in ,如下所示:

 include src/static/* include src/Potato/*.txt 

和它的工作(:

我不知道这是不是最好的出路,看起来像setup.py本身应该做到这一点,但无论如何工作…

以recursion方式包含所有文件:

 recursive-include project_name/templates * recursive-include project_name/static * 

其中project_name是您有setup.py文件的同一行中的一个文件夹。

根据文档,有三种方法可以包含软件包数据文件。 你有两个包:土豆和番茄。 静态目录不在这两个包中,所以这就是为什么setup.py中的package_data字典不起作用。 清单选项要求setup.py中的include_package_data设置为True。 访问非包数据文件可以按照这里find的方式完成。

使用以下

 packages = ['.','templates','static','docs'], package_data={'templates':['*'],'static':['*'],'docs':['*'],},