Skip to content

Fix Windows CLI entry point import error (ModuleNotFoundError: No module named 'cli')#51

Merged
JPrier merged 3 commits into
mainfrom
copilot/fix-44e57dd4-1c9d-4ad7-9ce6-bc485a3d8641
Sep 27, 2025
Merged

Fix Windows CLI entry point import error (ModuleNotFoundError: No module named 'cli')#51
JPrier merged 3 commits into
mainfrom
copilot/fix-44e57dd4-1c9d-4ad7-9ce6-bc485a3d8641

Conversation

Copilot AI commented Sep 27, 2025

Copy link
Copy Markdown
Contributor

Fixes the issue where running treeagent on Windows fails with:

ModuleNotFoundError: No module named 'cli'

Problem

Windows pip installations generate entry point scripts differently than Linux. When the pyproject.toml specifies:

[project.scripts]
treeagent = "src.cli:main"

Linux generates: from src.cli import main
Windows generates: from cli import main ← This fails

The Windows version tries to import cli directly but can't find it because the module is located at src.cli.

Solution

Added a compatibility layer that ensures both import patterns work:

  1. Primary fix: Created cli.py at the project root that imports and re-exports the main function from src.cli. This makes both import patterns valid:

    • from cli import main (what Windows expects)
    • from src.cli import main (original pattern)
  2. Backup method: Added src/treeagent/__main__.py to enable module execution via python -m src.treeagent as an alternative.

  3. 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 treeagent command should work correctly after reinstallation.

Files Changed

  • cli.py - New compatibility module with robust import handling
  • src/treeagent/__main__.py - New module execution entry point
  • README.md - Added Windows compatibility documentation
Original prompt

Im getting this issue when running locally on my windows machine

PS D:\Development\githubDesktop\TreeAgent> treeagent "hello"
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\Users\jkpri\AppData\Local\Programs\Python\Python313\Scripts\treeagent.exe_main
.py", line 2, in
from cli import main
ModuleNotFoundError: No module named 'cli'

The same version works fine on the github codespaces

@JPrier ➜ /workspaces/TreeAgent (main) $ treeagent "hello"
2025-09-27 20:37:45,395 [INFO] Executing root-task (REQUIREMENTS) using mock
2025-09-27 20:37:45,396 [INFO] REQUIREMENTS task completed: artifacts none
2025-09-27 20:37:45,396 [INFO] Executing root-task-hld (HLD) using mock
2025-09-27 20:37:45,397 [INFO] HLD task completed: artifacts none
Project Summary:
Completed Tasks: 2
In Progress Tasks: 0
Failed Tasks: 0
Queued Tasks: 0


💡 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.

Copilot AI and others added 2 commits September 27, 2025 20:50
Co-authored-by: JPrier <24302717+JPrier@users.noreply.github.com>
Co-authored-by: JPrier <24302717+JPrier@users.noreply.github.com>
Copilot AI changed the title Im getting this issue when running locally on my windows machine PS D:\Development\githubDesktop\TreeAgent> treeagent "hello" Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88... Fix Windows CLI entry point import error (ModuleNotFoundError: No module named 'cli') Sep 27, 2025
Copilot AI requested a review from JPrier September 27, 2025 20:54
@JPrier JPrier marked this pull request as ready for review September 27, 2025 21:05
@JPrier JPrier merged commit 47f439c into main Sep 27, 2025
4 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Comment thread cli.py
Comment on lines +1 to +21
"""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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants