{"id":"143604de69218842","repo":"pytest-dev/pytest","slug":"module-or-package-not-found-arg-missing-init","errorCode":null,"errorMessage":"module or package not found: {arg} (missing __init__.py?)","messagePattern":"module or package not found: (.+?) \\(missing __init__\\.py\\?\\)","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/main.py","lineNumber":1173,"sourceCode":"        raise UsageError(f\"path cannot contain [] parametrization: {arg}\")\n    parametrization = f\"{squacket}{rest}\" if squacket else None\n    module_name = None\n    if as_pypath:\n        pyarg_strpath = search_pypath(\n            strpath, consider_namespace_packages=consider_namespace_packages\n        )\n        if pyarg_strpath is not None:\n            module_name = strpath\n            strpath = pyarg_strpath\n    fspath = invocation_path / strpath\n    fspath = absolutepath(fspath)\n    if not safe_exists(fspath):\n        msg = (\n            \"module or package not found: {arg} (missing __init__.py?)\"\n            if as_pypath\n            else \"file or directory not found: {arg}\"\n        )\n        raise UsageError(msg.format(arg=arg))\n    if parts and fspath.is_dir():\n        msg = (\n            \"package argument cannot contain :: selection parts: {arg}\"\n            if as_pypath\n            else \"directory argument cannot contain :: selection parts: {arg}\"\n        )\n        raise UsageError(msg.format(arg=arg))\n    return CollectionArgument(\n        path=fspath,\n        parts=parts,\n        parametrization=parametrization,\n        module_name=module_name,\n        original_index=arg_index,\n    )\n\n\ndef is_collection_argument_subsumed_by(\n    arg: CollectionArgument, by: CollectionArgument","sourceCodeStart":1155,"sourceCodeEnd":1191,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/main.py#L1155-L1191","documentation":"Raised by `resolve_collection_argument` (with `as_pypath=True`) when a `--pyargs`/import-path style argument cannot be resolved to an importable module or package on sys.path. pytest searched `search_pypath` and found nothing, so it reports the argument and hints that `__init__.py` may be missing.","triggerScenarios":"Running `pytest --pyargs mypkg.tests.test_foo` when `mypkg` is not installed/importable, or when `mypkg/tests` lacks `__init__.py` (not a package). Also when the virtualenv containing the package is not activated.","commonSituations":"Forgetting to `pip install -e .` the package. Running from the wrong directory/venv. Namespace packages without `__init__.py` when `consider_namespace_packages` is off. Typo in the dotted module path.","solutions":["Install/import the package: `pip install -e .` or add its root to PYTHONPATH.","Add `__init__.py` to make the directory a proper package (or enable namespace packages via `--import-mode=importlib`).","Double-check the dotted path spelling and that the target venv is active.","Drop `--pyargs` and pass a filesystem path instead."],"exampleFix":"// before\n$ pytest --pyargs mypkg.tests.test_foo   # not importable\n// after\n$ pip install -e .\n$ pytest --pyargs mypkg.tests.test_foo","handlingStrategy":"validation","validationCode":"import importlib.util\n\ndef module_importable(dotted: str) -> bool:\n    return importlib.util.find_spec(dotted) is not None","typeGuard":"def is_importable_module(dotted: str) -> bool:\n    import importlib.util\n    try:\n        return importlib.util.find_spec(dotted) is not None\n    except (ModuleNotFoundError, ValueError):\n        return False","tryCatchPattern":null,"preventionTips":["pip install -e . the package before using --pyargs.","Ensure __init__.py exists for packages (or enable namespace packages).","Activate the correct virtualenv before running pytest."],"tags":["pytest","collection","pyargs","import","usageerror"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}