MANIFEST.in,package_data和data_files的说明? [英] MANIFEST.in, package_data, and data_files clarification?
问题描述
我正在尝试创建一个Python包,并且具有这样的目录结构:
I am trying to create a Python package, and I have a directory structure like this:
mypkg/
├── __init__.py
├── module1
│ ├── x.py
│ ├── y.py
│ └── z.txt
└── module2
├── a.py
└── b.py
然后我将所有文件添加到 MANIFEST.in
中,当我检查创建的存档时,它具有所有文件。
Then I added all the files in MANIFEST.in
and when I check the created archive, it had all the files.
当我在 dist-packages / mypkg /中执行
。我只看到Python文件,没有看到 python setup.py install
时module1 z.txt
。
When I do python setup.py install
in the dist-packages/mypkg/module1
. I see only the Python files and not z.txt
.
我有 z。 txt
在 MANIFEST.in
和 setup.py
中:
setup (
packages = [
'mypkg',
'mypkg.module1',
'mypkg.module2',
],
package_data = {
'mypkg': ['module1/z.txt']
},
include_package_data = True,
...
)
我尝试添加该文件也称为 data_files
,但在 / usr / local
中创建了一个目录。我想将其保存在源代码目录中,因为代码使用了这些数据。
I tried adding the file as data_files
as well but that created a directory in /usr/local
. I want to keep it inside the source code directory as the code uses that data.
我阅读了下面列出的信息,但对于正确的方法我一直感到困惑在 setup.py安装
之后,将 z.txt
保留在正确的位置。
I have read the posts listed below but I keep getting confused about what is the right way to keep z.txt
in the right location after setup.py install
.
- MANIFEST.in在 python setup.py install中被忽略-没有安装数据文件?
- 使用setup.py
- http://blog.codekills.net/2011/07/15/lies, -more-lies-and-python-packaging-documentation-on--package_data- /
- MANIFEST.in ignored on "python setup.py install" - no data files installed?
- Installing data files into site-packages with setup.py
- http://blog.codekills.net/2011/07/15/lies,-more-lies-and-python-packaging-documentation-on--package_data-/
推荐答案
更新:当我开始使用setuptools而不是distutils.core时,此问题已得到解决。我认为在setuptools正常工作而不修改代码的情况下,distutils与清单文件不符是一个问题。我建议将来使用setuptools。使用此处的链接:设置工具-开发人员指南
Update: It got fixed when I started using setuptools instead of distutils.core. I think it was some problem with distutils not agreeing with manifest while setuptools worked without any changes in the code. I recommend using setuptools in the future. Using the link here : setup tools- developers guide
这篇关于MANIFEST.in,package_data和data_files的说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!