A newer version of the Gradio SDK is available: 6.20.0
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.tomlwithwhere = ["src"]so setuptools knows where to lookpip 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.