【Flask-app.py运行】已解决Cannot run program “D:\APP\python\python.exe”

一、问题描述

Cannot run program “D:\APP\python\python.exe” (in directory “F:\Codes\竞赛\大计赛\group\code\web\web”): CreateProcess error=2, 系统找不到指定的文件。

这段报错源于运行 flask 项目的 app.py 时报错找不到程序,解决方法如下

二、解决方法

Traceback (most recent call last): File "d:\program files (x86)\python3.8.8\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "d:\program files (x86)\python3.8.8\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "D:\Program Files (x86)\python3.8.8\Scripts\mitmproxy.exe\__main__.py", line 7, in <module> File "d:\program files (x86)\python3.8.8\lib\site-packages\mitmproxy\tools\main.py", line 131, in mitmproxy from mitmproxy.tools import console File "d:\program files (x86)\python3.8.8\lib\site-packages\mitmproxy\tools\console\__init__.py", line 1, in <module> from mitmproxy.tools.console import master File "d:\program files (x86)\python3.8.8\lib\site-packages\mitmproxy\tools\console\master.py", line 19, in <module> from mitmproxy import addons File "d:\program files (x86)\python3.8.8\lib\site-packages\mitmproxy\addons\__init__.py", line 14, in <module> from mitmproxy.addons import onboarding File "d:\program files (x86)\python3.8.8\lib\site-packages\mitmproxy\addons\onboarding.py", line 2, in <module> from mitmproxy.addons.onboardingapp import app File "d:\program files (x86)\python3.8.8\lib\site-packages\mitmproxy\addons\onboardingapp\__init__.py", line 3, in <module> from flask import Flask, render_template File "d:\program files (x86)\python3.8.8\lib\site-packages\flask\__init__.py", line 7, in <module> from .app import Flask as Flask File "d:\program files (x86)\python3.8.8\lib\site-packages\flask\app.py", line 28, in <module> from . import cli File "d:\program files (x86)\python3.8.8\lib\site-packages\flask\cli.py", line 18, in <module> from .helpers import get_debug_flag File "d:\program files (x86)\python3.8.8\lib\site-packages\flask\helpers.py", line 16, in <module> from werkzeug.urls import url_quote ImportError: cannot import name 'url_quote' from 'werkzeug.urls' (d:\program files (x86)\python3.8.8\lib\site-packages\werkzeug\urls.py) 解释一下
06-19
PowerShell 7 环境已加载 (版本: 7.3.6) PowerShell 7 环境已加载 (版本: 7.3.6) PS C:\Users\Administrator\Desktop> # E:\AI_System\core\config_loader.py PS C:\Users\Administrator\Desktop> import sys import: The term 'import' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> import os import: The term 'import' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> import json import: The term 'import' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> from pathlib import Path ParserError: Line | 1 | from pathlib import Path | ~~~~ | The 'from' keyword is not supported in this version of the language. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> class ConfigLoader: >> def __init__(self, config_dir=None): ParserError: Line | 2 | def __init__(self, config_dir=None): | ~ | Missing 'class' body in 'class' declaration. PS C:\Users\Administrator\Desktop> # 设置默认配置目录 PS C:\Users\Administrator\Desktop> if not config_dir: ParserError: Line | 1 | if not config_dir: | ~ | Missing '(' after 'if' in if statement. PS C:\Users\Administrator\Desktop> config_dir = Path(__file__).resolve().parent.parent / "config" __file__: The term '__file__' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> self.config_dir = Path(config_dir) config_dir: The term 'config_dir' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> self.configs = {} self.configs: The term 'self.configs' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> def load_config(self, config_name): ParserError: Line | 1 | def load_config(self, config_name): | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> """加载指定配置文件""" "加载指定配置文件" PS C:\Users\Administrator\Desktop> # 支持多种文件格式 PS C:\Users\Administrator\Desktop> possible_extensions = [".json", ".yaml", ".yml", ".py"] possible_extensions: The term 'possible_extensions' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> config_path = None config_path: The term 'config_path' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 查找存在的配置文件 PS C:\Users\Administrator\Desktop> for ext in possible_extensions: ParserError: Line | 1 | for ext in possible_extensions: | ~ | Missing opening '(' after keyword 'for'. PS C:\Users\Administrator\Desktop> test_path = self.config_dir / f"{config_name}{ext}" test_path: The term 'test_path' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> if test_path.exists(): ParserError: Line | 1 | if test_path.exists(): | ~ | Missing '(' after 'if' in if statement. PS C:\Users\Administrator\Desktop> config_path = test_path config_path: The term 'config_path' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> break PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> if not config_path: ParserError: Line | 1 | if not config_path: | ~ | Missing '(' after 'if' in if statement. PS C:\Users\Administrator\Desktop> raise FileNotFoundError(f"配置文件不存在: {config_name} in {self.config_dir}") f配置文件不存在: {config_name} in {self.config_dir}: The term 'f配置文件不存在: {config_name} in {self.config_dir}' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 根据文件类型加载配置 PS C:\Users\Administrator\Desktop> if config_path.suffix == ".json": ParserError: Line | 1 | if config_path.suffix == ".json": | ~ | Missing '(' after 'if' in if statement. PS C:\Users\Administrator\Desktop> with open(config_path, 'r', encoding='utf-8') as f: ParserError: Line | 1 | with open(config_path, 'r', encoding='utf-8') as f: | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> self.configs[config_name] = json.load(f) f: The term 'f' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> elif config_path.suffix in [".yaml", ".yml"]: elif: The term 'elif' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> try: try:: The term 'try:' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> import yaml import: The term 'import' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> with open(config_path, 'r', encoding='utf-8') as f: ParserError: Line | 1 | with open(config_path, 'r', encoding='utf-8') as f: | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> self.configs[config_name] = yaml.safe_load(f) f: The term 'f' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> except ImportError: except: The term 'except' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> raise ImportError("请安装 PyYAML 库以支持 YAML 配置") raise: The term 'raise' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> elif config_path.suffix == ".py": elif: The term 'elif' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> # 动态导入 Python 配置文件 PS C:\Users\Administrator\Desktop> spec = importlib.util.spec_from_file_location(config_name, config_path) ParserError: Line | 1 | … spec = importlib.util.spec_from_file_location(config_name, config_ … | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> module = importlib.util.module_from_spec(spec) spec: The term 'spec' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> spec.loader.exec_module(module) spec.loader.exec_module: The term 'spec.loader.exec_module' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> self.configs[config_name] = module.__dict__ self.configs[config_name]: The term 'self.configs[config_name]' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> return self.configs[config_name] self.configs[config_name]: The term 'self.configs[config_name]' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> def get_config(self, config_name, default=None): ParserError: Line | 1 | def get_config(self, config_name, default=None): | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> """获取已加载的配置""" "获取已加载的配置" PS C:\Users\Administrator\Desktop> return self.configs.get(config_name, default or {}) ParserError: Line | 1 | return self.configs.get(config_name, default or {}) | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> def reload_config(self, config_name): ParserError: Line | 1 | def reload_config(self, config_name): | ~ | Missing argument in parameter list. PS C:\Users\Administrator\Desktop> """重新加载配置""" "重新加载配置" PS C:\Users\Administrator\Desktop> if config_name in self.configs: ParserError: Line | 1 | if config_name in self.configs: | ~ | Missing '(' after 'if' in if statement. PS C:\Users\Administrator\Desktop> del self.configs[config_name] PS C:\Users\Administrator\Desktop> return self.load_config(config_name) config_name: The term 'config_name' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 创建全局配置加载器实例 PS C:\Users\Administrator\Desktop> config_loader = ConfigLoader() ParserError: Line | 1 | config_loader = ConfigLoader() | ~ | An expression was expected after '('. PS C:\Users\Administrator\Desktop> # E:\AI_System\Start-Server.ps1 PS C:\Users\Administrator\Desktop> param( >> [switch]$DebugMode, >> [int]$Port = 5000, >> [string]$Env = "dev" >> ) PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 1. 设置项目根目录 PS C:\Users\Administrator\Desktop> $projectRoot = $PSScriptRoot PS C:\Users\Administrator\Desktop> Set-Location $projectRoot PS C:\Users\Administrator> PS C:\Users\Administrator> # 2. 激活虚拟环境 PS C:\Users\Administrator> $venvPath = Join-Path $projectRoot "web_ui\.venv" Join-Path: Cannot bind argument to parameter 'Path' because it is an empty string. PS C:\Users\Administrator> if (-not (Test-Path (Join-Path $venvPath "Scripts\Activate.ps1"))) { >> Write-Host "创建虚拟环境..." -ForegroundColor Yellow >> python -m venv $venvPath >> } InvalidOperation: The variable '$venvPath' cannot be retrieved because it has not been set. PS C:\Users\Administrator> PS C:\Users\Administrator> . (Join-Path $venvPath "Scripts\Activate.ps1") InvalidOperation: The variable '$venvPath' cannot be retrieved because it has not been set. PS C:\Users\Administrator> Write-Host "虚拟环境已激活 ($(python --version))" -ForegroundColor Green 虚拟环境已激活 (Python 3.10.10) PS C:\Users\Administrator> PS C:\Users\Administrator> # 3. 安装依赖 PS C:\Users\Administrator> $requirements = Join-Path $projectRoot "requirements.txt" Join-Path: Cannot bind argument to parameter 'Path' because it is an empty string. PS C:\Users\Administrator> if (Test-Path $requirements) { >> pip install -r $requirements >> } InvalidOperation: The variable '$requirements' cannot be retrieved because it has not been set. PS C:\Users\Administrator> PS C:\Users\Administrator> # 4. 设置环境变量 PS C:\Users\Administrator> $env:AI_ENV = $Env PS C:\Users\Administrator> $env:FLASK_APP = "server.py" PS C:\Users\Administrator> $env:FLASK_ENV = if ($DebugMode) { "development" } else { "production" } PS C:\Users\Administrator> PS C:\Users\Administrator> # 5. 启动服务器 PS C:\Users\Administrator> if ($DebugMode) { >> Write-Host "启动调试模式 (端口: $Port)..." -ForegroundColor Cyan >> python -m debugpy --listen 0.0.0.0:$Port -m flask run --port $Port >> } else { >> Write-Host "启动生产模式 (端口: $Port)..." -ForegroundColor Cyan >> python -m flask run --port $Port >> } 启动生产模式 (端口: 5000)... Disabling PyTorch because PyTorch >= 2.1 is required but found 2.0.0 None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used. Traceback (most recent call last): File "E:\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "E:\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "E:\Python310\lib\site-packages\flask\__main__.py", line 3, in <module> main() File "E:\Python310\lib\site-packages\flask\cli.py", line 1131, in main cli.main() File "E:\Python310\lib\site-packages\click\core.py", line 1363, in main rv = self.invoke(ctx) File "E:\Python310\lib\site-packages\click\core.py", line 1830, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "E:\Python310\lib\site-packages\click\core.py", line 1226, in invoke return ctx.invoke(self.callback, **ctx.params) File "E:\Python310\lib\site-packages\click\core.py", line 794, in invoke return callback(*args, **kwargs) File "E:\Python310\lib\site-packages\click\decorators.py", line 93, in new_func return ctx.invoke(f, obj, *args, **kwargs) File "E:\Python310\lib\site-packages\click\core.py", line 794, in invoke return callback(*args, **kwargs) File "E:\Python310\lib\site-packages\flask\cli.py", line 979, in run_command raise e from None File "E:\Python310\lib\site-packages\flask\cli.py", line 963, in run_command app: WSGIApplication = info.load_app() # pyright: ignore File "E:\Python310\lib\site-packages\flask\cli.py", line 349, in load_app app = locate_app(import_name, name) File "E:\Python310\lib\site-packages\flask\cli.py", line 245, in locate_app __import__(module_name) File "C:\Users\Administrator\server.py", line 3, in <module> from transformers import pipeline File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist File "E:\Python310\lib\site-packages\transformers\utils\import_utils.py", line 2292, in __getattr__ module = self._get_module(self._class_to_module[name]) File "E:\Python310\lib\site-packages\transformers\utils\import_utils.py", line 2322, in _get_module raise e File "E:\Python310\lib\site-packages\transformers\utils\import_utils.py", line 2320, in _get_module return importlib.import_module("." + module_name, self.__name__) File "E:\Python310\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "E:\Python310\lib\site-packages\transformers\pipelines\__init__.py", line 29, in <module> from ..models.auto.image_processing_auto import IMAGE_PROCESSOR_MAPPING, AutoImageProcessor File "E:\Python310\lib\site-packages\transformers\models\auto\image_processing_auto.py", line 28, in <module> from ...image_processing_utils_fast import BaseImageProcessorFast File "E:\Python310\lib\site-packages\transformers\image_processing_utils_fast.py", line 43, in <module> from .processing_utils import Unpack File "E:\Python310\lib\site-packages\transformers\processing_utils.py", line 36, in <module> from .audio_utils import load_audio File "E:\Python310\lib\site-packages\transformers\audio_utils.py", line 39, in <module> import soundfile as sf File "E:\Python310\lib\site-packages\soundfile.py", line 212, in <module> _snd = _ffi.dlopen(_explicit_libname) OSError: cannot load library 'libsndfile.dll': error 0x7e PS C:\Users\Administrator> # E:\AI_System\web_ui\server.py PS C:\Users\Administrator> import os import: The term 'import' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> import sys import: The term 'import' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> from pathlib import Path ParserError: Line | 1 | from pathlib import Path | ~~~~ | The 'from' keyword is not supported in this version of the language. PS C:\Users\Administrator> from flask import Flask, jsonify ParserError: Line | 1 | from flask import Flask, jsonify | ~~~~ | The 'from' keyword is not supported in this version of the language. PS C:\Users\Administrator> PS C:\Users\Administrator> # 添加项目根目录到搜索路径 PS C:\Users\Administrator> project_root = Path(__file__).resolve().parent.parent __file__: The term '__file__' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> sys.path.insert(0, str(project_root)) ParserError: Line | 1 | sys.path.insert(0, str(project_root)) | ~ | Missing expression after ','. PS C:\Users\Administrator> PS C:\Users\Administrator> print(f"项目根目录: {project_root}") f项目根目录: {project_root}: The term 'f项目根目录: {project_root}' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> PS C:\Users\Administrator> # 导入配置加载器 PS C:\Users\Administrator> from core.config_loader import config_loader ParserError: Line | 1 | from core.config_loader import config_loader | ~~~~ | The 'from' keyword is not supported in this version of the language. PS C:\Users\Administrator> PS C:\Users\Administrator> app = Flask(__name__) __name__: The term '__name__' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> PS C:\Users\Administrator> # 加载配置 PS C:\Users\Administrator> try: try:: The term 'try:' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> system_config = config_loader.load_config("system_config") system_config: The term 'system_config' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> hardware_config = config_loader.load_config("hardware_config") hardware_config: The term 'hardware_config' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> model_config = config_loader.load_config("model_registry") model_config: The term 'model_config' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> except Exception as e: except: The term 'except' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> print(f"配置加载错误: {e}") f配置加载错误: {e}: The term 'f配置加载错误: {e}' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> system_config = {} system_config: The term 'system_config' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> hardware_config = {} hardware_config: The term 'hardware_config' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> model_config = {} model_config: The term 'model_config' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> PS C:\Users\Administrator> @app.route('/') ParserError: Line | 1 | @app.route('/') | ~~~~ | The splatting operator '@' cannot be used to reference variables in an expression. '@app' can be used only as an | argument to a command. To reference variables in an expression use '$app'. PS C:\Users\Administrator> def index(): ParserError: Line | 1 | def index(): | ~ | An expression was expected after '('. PS C:\Users\Administrator> return jsonify({ >> "status": "running", >> "project_root": str(project_root), >> "system_config": system_config >> }) ParserError: Line | 2 | "status": "running", | ~ | Unexpected token ':' in expression or statement. PS C:\Users\Administrator> PS C:\Users\Administrator> @app.route('/config/<name>') ParserError: Line | 1 | @app.route('/config/<name>') | ~~~~ | The splatting operator '@' cannot be used to reference variables in an expression. '@app' can be used only as an | argument to a command. To reference variables in an expression use '$app'. PS C:\Users\Administrator> def get_config(name): name: The term 'name' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> config = config_loader.get_config(name, {}) ParserError: Line | 1 | config = config_loader.get_config(name, {}) | ~ | Missing argument in parameter list. PS C:\Users\Administrator> return jsonify(config) config: The term 'config' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> PS C:\Users\Administrator> if __name__ == '__main__': ParserError: Line | 1 | if __name__ == '__main__': | ~ | Missing '(' after 'if' in if statement. PS C:\Users\Administrator> port = int(os.getenv('FLASK_PORT', 5000)) InvalidOperation: The function or command was called as if it were a method. Parameters should be separated by spaces. For information about parameters, see the about_Parameters Help topic. PS C:\Users\Administrator> app.run(host='0.0.0.0', port=port) ParserError: Line | 1 | app.run(host='0.0.0.0', port=port) | ~ | Missing argument in parameter list. PS C:\Users\Administrator> # 创建启动脚本 PS C:\Users\Administrator> $startScript = @' >> param( >> [switch]$DebugMode, >> [int]$Port = 5000, >> [string]$Env = "dev" >> ) >> >> $projectRoot = $PSScriptRoot >> Set-Location $projectRoot >> >> # ... 完整脚本内容 ... >> '@ PS C:\Users\Administrator> PS C:\Users\Administrator> Set-Content -Path "E:\AI_System\Start-Server.ps1" -Value $startScript -Encoding UTF8 PS C:\Users\Administrator> PS C:\Users\Administrator> # 创建快捷函数 PS C:\Users\Administrator> function Start-AIServer { >> param( >> [switch]$Debug, >> [int]$Port = 5000 >> ) >> >> & "E:\AI_System\Start-Server.ps1" -DebugMode:$Debug -Port $Port >> } PS C:\Users\Administrator> PS C:\Users\Administrator> # 添加到配置文件 PS C:\Users\Administrator> $profileContent = @" >> # AI 系统快捷命令 >> function Start-AIServer { >> param([switch]`$Debug, [int]`$Port = 5000) >> & "E:\AI_System\Start-Server.ps1" -DebugMode:`$Debug -Port `$Port >> } >> >> Set-Alias aistart Start-AIServer >> "@ PS C:\Users\Administrator> PS C:\Users\Administrator> Add-Content -Path $PROFILE -Value $profileContent -Encoding UTF8 PS C:\Users\Administrator> # 1. 打开 PowerShell PS C:\Users\Administrator> & "$env:ProgramFiles\PowerShell\7\pwsh.exe" PowerShell 7.3.6 A new PowerShell stable release is available: v7.5.2 Upgrade now, or check out the release page at: https://aka.ms/PowerShell-Release?tag=v7.5.2 PowerShell 7 环境已加载 (版本: 7.3.6) PS C:\Users\Administrator> # 热重载配置 PS C:\Users\Administrator> @app.route('/reload/<name>') ParserError: Line | 1 | @app.route('/reload/<name>') | ~~~~ | The splatting operator '@' cannot be used to reference variables in an expression. '@app' can be used only as an | argument to a command. To reference variables in an expression use '$app'. PS C:\Users\Administrator> def reload_config(name): name: The term 'name' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> try: try:: The term 'try:' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> config_loader.reload_config(name) name: The term 'name' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> return jsonify({"status": "success", "config": name}) ParserError: Line | 1 | return jsonify({"status": "success", "config": name}) | ~ | Unexpected token ':' in expression or statement. PS C:\Users\Administrator> except Exception as e: except: The term 'except' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> return jsonify({"status": "error", "message": str(e)}), 500 ParserError: Line | 1 | return jsonify({"status": "error", "message": str(e)}), 500 | ~ | Unexpected token ':' in expression or statement. PS C:\Users\Administrator> # 根据环境加载不同配置 PS C:\Users\Administrator> env = os.getenv("AI_ENV", "dev") env: The term 'env' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> config_loader.load_config(f"system_config_{env}") fsystem_config_{env}: The term 'fsystem_config_{env}' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> # 配置回退机制 PS C:\Users\Administrator> try: try:: The term 'try:' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> model_config = config_loader.load_config("model_registry") model_config: The term 'model_config' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> except FileNotFoundError: except: The term 'except' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator> model_config = config_loader.load_config("default_model_registry") model_config: The term 'model_config' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. PS C:\Users\Administrator>
最新发布
08-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向 阳 花

感谢大佬支持,本人会继续努力哒

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值