fix: 运行方式改回脚本并自注入项目根,修复 Windows No module named 'src'
- 现象:Windows(Python 3.7) python -m src.main 报 No module named 'src', 即便 cwd 在项目根、src/__init__.py 存在。 - 根因:该环境运行时不把当前目录加入 sys.path,python -m 找不到 cwd 下的 src 包。 - 修复: - src/main.py 启动时自注入项目根到 sys.path,不依赖运行环境配置; - 运行方式从 python -m src.main 改回脚本方式 python src/main.py; - dev.bat 恢复 CRLF 行尾并改用 python src\main.py; - 00/03/05/current-state 文档命令同步。 验证:WSL 下从不含 src 的目录脚本方式运行 exit=0;unittest 17 passed。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b1e38ffd7a
commit
c204fc205c
@@ -39,7 +39,7 @@
|
||||
|
||||
```powershell
|
||||
# 本地运行入口
|
||||
python -m src.main
|
||||
python src/main.py
|
||||
|
||||
# 测试
|
||||
python -m unittest discover -s tests -t .
|
||||
|
||||
Reference in New Issue
Block a user