python data_error ai_generated true

ModuleNotFoundError:没有名为 'mypkg.data' 的模块 # 在从 sdist 执行 pip install mypkg 之后

ModuleNotFoundError: No module named 'mypkg.data' # after: pip install mypkg from sdist

ID: python/setuptools-sdist-missing-package-data

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
0证据数
2024-06-30首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

非 Python 数据文件或子包未包含在 sdist 中,因为 package_data/include_package_data 或 MANIFEST.in 配置错误。

English

Non-Python data files or subpackages were not included in the sdist because package_data/include_package_data or MANIFEST.in were misconfigured.

generic

解决方案

  1. 95% 成功率
    [tool.setuptools.package-data]
    mypkg = ["data/*.json", "data/*.csv"]
    # or
    [tool.setuptools]
    include-package-data = true
  2. 90% 成功率
    echo 'recursive-include mypkg/data *.json *.csv' >> MANIFEST.in
    python -m build --sdist
    pip install dist/mypkg-1.0.tar.gz

无效尝试

常见但无效的做法:

  1. 90% 失败

    Forces building from sdist, which is exactly where the data files are missing.

  2. 85% 失败

    Reinstall does not add missing files to the sdist.

  3. 80% 失败

    .gitignore does not affect sdist contents; MANIFEST.in does.