使用 setup.py 在 Python 包中包含资源 [英] Including resources in a Python package using setup.py
问题描述
我正在做一个网站项目.
I'm working on a website project.
当我使用 setup.py 并运行 setup.py build 时,构建脚本排除了我网站中的所有资源(基本上是所有非 python 文件).我做错了什么?
When I use setup.py and run setup.py build, the build script excludes all of the resources in my web site (basically all of the non python files). What am I doing wrong?
推荐答案
我发现使用 distutils 是提供一个MANIFEST.in 文件.将此文件放在与您的 setup.py
相同的目录中,并在其中包含您需要的资源文件列表.例如,您的 MANIFEST.in
文件可能是这样的:
The most reliable way I've found to include extra files in a distribution using distutils is to provide a MANIFEST.in file. Place this file in the same directory as your setup.py
and include in it the list of resource files you require. For example, your MANIFEST.in
file might like this:
include resources/somefile.txt resources/*.png
recursive-include resources/static *.png *.jpg *.css *.js
有关详细信息,请参阅 distutils 文档.
See the distutils documentation for more details.
虽然我更喜欢 MANIFEST.in 方法,如果您使用setuptools 或分发,看看这个 answer 用于做同样事情的替代方法.
Though I prefer the MANIFEST.in method, if you are using setuptools or distribute, have a look at this answer for an alternative method of doing the same thing.
这篇关于使用 setup.py 在 Python 包中包含资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!