运行ReactPy示例脚本遇‘RuntimeError: No built-in server...’错误的原因
问题:运行ReactPy入门示例时触发RuntimeError错误
我运行ReactPy入门示例命令:
python -c "import reactpy; reactpy.run(reactpy.sample.SampleApp)"
时,触发了RuntimeError: No built-in server implementation installed.错误。该示例来自一篇入门教程,且python -m http.server可正常运行。
完整堆栈信息如下:
python -c "import reactpy; reactpy.run(reactpy.sample.SampleApp)" 2023-06-11T02:37:17+0300 | WARNING | The `run()` function is only intended for testing during development! To run in production, consider selecting a supported backend and importing its associated `configure()` function from `reactpy.backend.<package>` where `<package>` is one of ['starlette', 'fastapi', 'sanic', 'tornado', 'flask']. For details refer to the docs on how to run each package. Traceback (most recent call last): File "/opt/homebrew/lib/python3.11/site-packages/reactpy/backend/default.py", line 59, in _default_implementation implementation = next(all_implementations()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ StopIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<string>", line 1, in <module> File "/opt/homebrew/lib/python3.11/site-packages/reactpy/backend/utils.py", line 37, in run app = implementation.create_development_app() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/reactpy/backend/default.py", line 28, in create_development_app return _default_implementation().create_development_app() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/reactpy/backend/default.py", line 62, in _default_implementation raise RuntimeError("No built-in server implementation installed.")
原因分析
- ReactPy的
reactpy.run()方法依赖后端Web框架实现,默认安装的ReactPy仅包含核心库,不会自动附带任何后端依赖 - 缺少官方支持的后端框架(如Starlette、FastAPI、Flask等),导致无法启动开发服务器
python -m http.server是Python内置静态文件服务器,和ReactPy需要的动态Web后端不属于同一类服务,因此它能正常运行不代表满足ReactPy的依赖要求
解决方法
安装任意一个ReactPy支持的后端框架即可,示例如下:
- 安装Flask:
pip install flask
- 或安装Starlette:
pip install starlette
安装完成后重新运行示例命令即可正常启动。
内容的提问来源于stack exchange,提问作者jeremy_rutman
相关产品推荐
相关产品推荐

