python config_error ai_generated true

错误:每个包目录中必须有一个__init__.py文件

error: Each package must have an __init__.py file in its directory

ID: python/setuptools-package-init-missing

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

版本兼容性

版本状态引入弃用备注
3.8 active

根因分析

在旧版本或某些配置中,setuptools要求包目录中包含__init__.py文件。

English

Setuptools requires __init__.py for package discovery in older versions or certain configurations.

generic

解决方案

  1. 95% 成功率 Create __init__.py in every package directory
    find . -type d -name 'mypackage' -exec touch {}/__init__.py \;
  2. 90% 成功率 Use find_packages with exclude or namespace packages
    from setuptools import find_packages
    setup(packages=find_packages(include=['mypackage*']))

无效尝试

常见但无效的做法:

  1. Adding empty __init__.py to root only 80% 失败

    Each subpackage directory needs its own __init__.py.

  2. Removing the package from setup.py 60% 失败

    Excludes package from distribution; not a fix.