typer helloworld.main run
raises ModuleNotFoundError, but py -m typer helloworld.main run
works
#1253
Unanswered
martyszewski
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Hi! I have a minimal setup:
In
main.py
I define a simple Typer app: (see example code)I activate the virtual environment and install typer. Then:
py -m helloworld.main
workstyper helloworld.main run
fails withModuleNotFoundError: No module named 'helloworld'
typer helloworld\main.py run
workspy -m typer helloworld.main run
worksIt seems the
typer
CLI is executed from.venv/Scripts
, so the project root isn’t onsys.path
.Launching with
python -m typer helloworld.main run
orPYTHONPATH=. typer …
fixes it.Is this the intended behaviour? Would it make sense for the
typer
launcher to prepend the CWD tosys.path
(mirroringpython -m
), or should the docs recommend usingpython -m typer
during local development?I’ve read the docs at https://typer.tiangolo.com/tutorial/typer-command/#run-a-package-or-module and expected
typer helloworld.main run
to work too.Is this a misunderstanding on my side about how typer resolves modules, or is there an import context difference between typer and python -m?
Thanks in advance for clarifying!
Operating System
Windows
Operating System Details
Guest OS: Windows 11 — clean installation, no third-party tweaks
Python: CPython 3.13.5 (64-bit) — installed from the official python.org installer, added to
PATH
Extra tooling:
pip
25.x (bundled), Typer 0.16.x, Rich 14.x — installed in an isolated virtual-env (python -m venv .venv
)Typer Version
0.16.0
Python Version
3.13.5
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions