如何使用package_data在PyPi包中包含文件

时间:2019-07-02 14:31:06

标签: python setuptools

我试图了解如何在package_data中使用setup.py来为私有pypiserver正确打包数据。我的文件夹结构如下:

.
└── elastic-manager/
    ├── elastic_manager/
    │   ├── icons/
    |   |   └──icon.svg
    │   └── lib/
    │       ├── acc/
    │       │   ├── elastic/
    │       │   │   └── query/
    │       │   └── mapping/
    │       ├── views/
    │       └── widgets/
    │           └── json_tree/
    │               ├── edit/
    │               └── input/
    ├── dist/
    └── setup.py

我正在尝试将图标包含在icons文件夹下。以下是我的setup.py的内容:

import setuptools

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
    name="elastic-manager",
    version="0.0.6",
    description="A graphical application to manage Elasticsearch.",
    long_description=long_description,
    long_description_content_type="text/markdown",
    packages=setuptools.find_packages(),
    include_package_data=True,
    package_data={
        "elastic_manager": ["icons/*"]
    },
    install_requires=[
        "PyQt5>=5.12",
        "pytz>=2019.1",
        "pyYAML>=5.1",
        "numpy>=1.16",
        "simplejson>=3.16",
        "elasticsearch>=7.0"
    ],
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Programming Language :: Python :: 3",
        "License :: Non-permissive",
        "Operating System :: OS Independent",
    ],
)

当我使用python3 setup.py sdist打包并使用生成的pip3中的tar.gz安装它时,我可以启动该程序,但是其中不包含图标!我怎么了?

谢谢!

1 个答案:

答案 0 :(得分:0)

我误解了package_data的目的。我应该按照指南中的指定在根目录中创建一个MANIFEST.inhttps://packaging.python.org/guides/distributing-packages-using-setuptools/#manifest-in

要在图标文件夹下包含所有内容,我必须添加行include elastic_manager/icons/*

感谢@hoefling