python - 如何制作 pip 安装包数据(配置文件)?

标签 python python-3.x setuptools python-packaging

我有一个名为 clana(GithubPyPI)的包,其结构如下:

.
├── clana
│   ├── cli.py
│   ├── config.yaml
│   ├── __init__.py
│   ├── utils.py
│   └── visualize_predictions.py
├── docs/
├── setup.cfg
├── setup.py
├── tests/
└── tox.ini

setup.py 看起来像这样:

from setuptools import find_packages
from setuptools import setup

requires_tests = [...]

install_requires = [...]


config = {
    "name": "clana",
    "version": "0.3.6",
    "author": "Martin Thoma",
    "author_email": "info@martin-thoma.de",
    "maintainer": "Martin Thoma",
    "maintainer_email": "info@martin-thoma.de",
    "packages": find_packages(),
    "entry_points": {"console_scripts": ["clana=clana.cli:entry_point"]},
    "install_requires": install_requires,
    "tests_require": requires_tests,
    "package_data": {"clana": ["clana/config.yaml"]},
    "include_package_data": True,
    "zip_safe": False,
}

setup(**config)

如何检查它是否不起作用

快速

python3 setup.py sdist
open dist/clana-0.3.8.tar.gz  # config.yaml is not in this file

真正的检查

我认为这将确保 config.yaml 在安装包时与 cli.py 位于同一目录中。但是当我尝试这个时:

virtualenv venv
source venv/bin/activate
pip install clana
cd venv/lib/python3.6/site-packages/clana
ls

我得到:

cli.py  __init__.py  __pycache__  utils.py  visualize_predictions.py

我上传到 PyPI 的方式:

python3 setup.py sdist bdist_wheel && twine upload dist/*

因此缺少 config.yaml。我怎样才能确定它在那里?

最佳答案

您可以在 setup.py 旁边添加一个文件名 MANIFEST.in,其中包含您要添加的文件列表,允许使用通配符(例如: include *.yamlinclude clana/config.yaml) 然后选项 include_package_data=True 将激活 list 文件

关于python - 如何制作 pip 安装包数据(配置文件)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58038169/

相关文章:

python - 如何在 Python 3 中将二进制流缓冲区写入文件而不显式读取它?

python - Tensorflow 保留所有文件。如何防止这种情况?

python - 正则表达式有额外的斜杠

python - 使用 BERT 模型进行推理时没有batch_size

python - 更改 setup.py 中的输出目录

python - 如何知道哪个Python受到pip命令的影响?

python - pip 安装私有(private)包

python - 有序坐标

python - 如果数字是 1 位,则预先打印一个空格

Python3 utf-8 解码问题