MANIFEST.in, package_data, and data_files clarification?

我与影子孤独终老i 提交于 2020-07-17 07:16:02

问题


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

Then I added all the files in MANIFEST.in and when I check the created archive, it had all the files.

When I do python setup.py install in the dist-packages/mypkg/module1. I see only the Python files and not z.txt.

I have z.txt in both MANIFEST.in and setup.py:

setup (
    packages = [
        'mypkg',
        'mypkg.module1',
        'mypkg.module2',
    ],
    package_data = {
        'mypkg': ['module1/z.txt']
    },
    include_package_data = True, 
    ...
)

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.

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 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-/

回答1:


Try using setuptools instead of distutils.




回答2:


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



来源:https://stackoverflow.com/questions/14422340/manifest-in-package-data-and-data-files-clarification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!