nmt-seq2seq-translator / docs /errors /module_not_found_src_layout.md
Mohammed Benguerine
Updat file module_not_found_src_layout.md
2586dca
|
Raw
History Blame Contribute Delete
1.83 kB

A newer version of the Gradio SDK is available: 6.20.0

Upgrade

ModuleNotFoundError β€” src/ layout not configured

Date: 2026-04-11
Project: Neural Machine Translation β€” AI Translator
Environment: Windows 11, Python 3.12.9


Error message

tests\test_languages.py:5: in <module>
    from ai_translator.languages import (
E   ModuleNotFoundError: No module named 'ai_translator'

Context

Running pytest after confirming pytest was installed. The project uses a src/ layout β€” all source code lives inside src/ai_translator/ instead of the root.

Why it happened

Python searches the root folder for packages by default. With a src/ layout, the package is one level deeper and Python can't find it without explicit configuration. Additionally, the package was never registered in the environment.

Neural Machine Translation β€” AI Translator structure

Neural Machine Translation β€” AI Translator/
β”œβ”€β”€ src/
β”‚   └── ai_translator/      ← Python couldn't find this
β”‚       β”œβ”€β”€ __init__.py
β”‚       └── languages.py
β”œβ”€β”€ tests/
β”‚   └── test_languages.py
└── pyproject.toml

What fixed it

Step 1 β€” Created pyproject.toml in the root folder:

[build-system]
requires = ["setuptools>=64"]
build-backend = "setuptools.build_meta"

[project]
name = "ai_translator"
version = "0.1.0"

[tool.setuptools.packages.find]
where = ["src"]

Step 2 β€” Installed the package in editable mode:

pip install -e .

Lesson learned

The src/ layout requires two things to work:

  • pyproject.toml with where = ["src"] so setuptools knows where to look
  • pip install -e . to register the package in the active environment

The -e flag means editable β€” Python points directly to your src/ folder, so code changes are reflected immediately without reinstalling.