Fix Windows CLI entry point import error (ModuleNotFoundError: No module named 'cli')#51
Conversation
Co-authored-by: JPrier <24302717+JPrier@users.noreply.github.com>
Co-authored-by: JPrier <24302717+JPrier@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
| """CLI entry point compatibility module. | ||
|
|
||
| This module provides compatibility for Windows installations where | ||
| entry points might resolve differently. It imports and re-exports | ||
| the main function from the actual CLI module. | ||
|
|
||
| This addresses the issue where Windows pip installations generate entry scripts | ||
| that import 'cli' instead of 'src.cli', causing ModuleNotFoundError. | ||
| """ | ||
|
|
||
| try: | ||
| # Try to import from the src package structure (development/editable install) | ||
| from src.cli import main | ||
| except ImportError: | ||
| # Fallback for potential different package structures | ||
| try: | ||
| from .cli import main | ||
| except ImportError: | ||
| raise ImportError("Could not import CLI main function from either src.cli or .cli") | ||
|
|
||
| __all__ = ['main'] No newline at end of file |
There was a problem hiding this comment.
[P1] Ensure compatibility shim is packaged
The new cli.py makes the Windows entry-point import succeed only when the file is present in the installation, but the build configuration (pyproject.toml packages only the src directory) does not include top-level modules. A wheel built from this repo will still omit cli.py, so treeagent.exe on Windows continues to raise ModuleNotFoundError: No module named 'cli'. Consider moving this shim into the src package or updating the packaging configuration so the module is shipped.
Useful? React with 👍 / 👎.
Fixes the issue where running
treeagenton Windows fails with:Problem
Windows pip installations generate entry point scripts differently than Linux. When the
pyproject.tomlspecifies:Linux generates:
from src.cli import mainWindows generates:
from cli import main← This failsThe Windows version tries to import
clidirectly but can't find it because the module is located atsrc.cli.Solution
Added a compatibility layer that ensures both import patterns work:
Primary fix: Created
cli.pyat the project root that imports and re-exports the main function fromsrc.cli. This makes both import patterns valid:from cli import main(what Windows expects)from src.cli import main(original pattern)Backup method: Added
src/treeagent/__main__.pyto enable module execution viapython -m src.treeagentas an alternative.Documentation: Updated README with Windows compatibility note.
Testing
Both execution methods work correctly on all platforms:
treeagent "your prompt"(primary method)python -m src.treeagent "your prompt"(backup method)The fix is backward compatible and doesn't affect existing functionality. Users experiencing the Windows import issue now have a reliable workaround, and the primary
treeagentcommand should work correctly after reinstallation.Files Changed
cli.py- New compatibility module with robust import handlingsrc/treeagent/__main__.py- New module execution entry pointREADME.md- Added Windows compatibility documentationOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.