"""Offline Python verification lab for PyCharm Chapter 04 (windows-install)."""
import json
import re
from pathlib import PureWindowsPath
VERSION = "CPython 3.12.14 offline PyCharm workflow verifier (desktop IDE not launched)"
def case_windows_installer_and_default_path():
installer = "pycharm-community-2026.1.0.exe"
install_dir = PureWindowsPath(r"C:\Program Files\JetBrains\PyCharm Community Edition 2026.1")
bin_dir = install_dir / "bin"
cli_cmd = "pycharm"
expected = {
"installer_matches": True,
"vendor_folder": "JetBrains",
"bin_path": r"C:\Program Files\JetBrains\PyCharm Community Edition 2026.1\bin",
"cli_command": "pycharm",
}
actual = {
"installer_matches": bool(re.match(r"^pycharm-(community-)?\d{4}\.\d+(\.\d+)?\.exe$", installer)),
"vendor_folder": install_dir.parent.name,
"bin_path": str(bin_dir),
"cli_command": cli_cmd,
}
return {
"name": "windows_installer_and_default_path",
"summary": "校验 Windows 安装包命名规则、默认安装路径、bin 目录及 pycharm 命令行入口",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_installer_options_checklist():
options = [
("Create Desktop Shortcut", True, "shortcut"),
('Add "Open Folder as Project"', True, "context_menu"),
("Add to PATH", True, "env_path_requires_reboot"),
("Associate .py files", True, "file_assoc"),
]
needs_reboot = any(tag == "env_path_requires_reboot" and enabled for _, enabled, tag in options)
expected = {
"option_count": 4,
"recommended_enabled": 4,
"reboot_recommended_for_path": True,
}
actual = {
"option_count": len(options),
"recommended_enabled": sum(1 for _, enabled, _ in options if enabled),
"reboot_recommended_for_path": needs_reboot,
}
return {
"name": "installer_options_checklist",
"summary": "核对 Windows 安装向导第 7 步 4 项勾选配置及 PATH 生效重启提示",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_post_install_config_and_keymap():
config_items = {
"UI 主题": {"default": "Darcula", "alt": "Light"},
"键盘映射": {"default": "IntelliJ", "alternatives": ["VS Code", "Eclipse"]},
"中文语言包": {"plugin": "Chinese (Simplified) Language Pack", "requires_restart": True},
"Python 解释器": {"settings_path": "File → Settings → Project → Python Interpreter"},
}
expected = {
"item_count": 4,
"default_keymap": "IntelliJ",
"zh_plugin_name": "Chinese (Simplified) Language Pack",
"interpreter_menu": "File → Settings → Project → Python Interpreter",
}
actual = {
"item_count": len(config_items),
"default_keymap": config_items["键盘映射"]["default"],
"zh_plugin_name": config_items["中文语言包"]["plugin"],
"interpreter_menu": config_items["Python 解释器"]["settings_path"],
}
return {
"name": "post_install_config_and_keymap",
"summary": "核对安装后 UI 主题、键盘映射、简体中文语言包与 Python 解释器配置路径",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_interpreter_path_resolution():
sample_path = PureWindowsPath(r"C:\Users\Developer\AppData\Local\Programs\Python\Python312\python.exe")
status_before = "No Python interpreter configured"
resolved = sample_path.name == "python.exe" and "Python312" in sample_path.parts
expected = {
"initial_warning": "No Python interpreter configured",
"exe_name": "python.exe",
"major_minor_folder": "Python312",
"resolved_valid": True,
}
actual = {
"initial_warning": status_before,
"exe_name": sample_path.name,
"major_minor_folder": sample_path.parent.name,
"resolved_valid": resolved,
}
return {
"name": "interpreter_path_resolution",
"summary": "验证 Windows 下手动定位 Python 解释器路径以解决未配置解释器告警的规则",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = [
case_windows_installer_and_default_path(),
case_installer_options_checklist(),
case_post_install_config_and_keymap(),
case_interpreter_path_resolution(),
]
print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
本例需在 Windows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。
入口文件:projects/pycharm-windows-install-lab/explore-windows-install.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-windows-install.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联17章) · 含当前章节或实例 · mbskycom202612a2240.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2257.zip