python module_error ai_generated true

ModuleNotFoundError:没有名为 'mypkg.subpkg' 的模块

ModuleNotFoundError: No module named 'mypkg.subpkg'

ID: python/setuptools-find-packages-missing-subpackage

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

版本兼容性

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

根因分析

setuptools.find_packages() 未包含该子包,因为它缺少 __init__.py 或被排除模式过滤掉了。

English

setuptools.find_packages() did not include the subpackage because it lacks an __init__.py or was excluded by patterns.

generic

解决方案

  1. 95% 成功率
    `touch mypkg/subpkg/__init__.py` then rebuild and reinstall the wheel.
  2. 92% 成功率
    In setup.py: `from setuptools import find_namespace_packages` then `packages=find_namespace_packages(include=['mypkg*'])`.

无效尝试

常见但无效的做法:

  1. 95% 失败

    install_requires lists external deps, not local packages.

  2. 70% 失败

    Breaks on upgrade and hides the packaging bug.