You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Replit中使用Eel遇OSError:无法找到Google Chrome/Chromium求解决

解决Replit中Eel找不到Chrome/Chromium的问题

步骤1:在Replit中安装Chromium

Replit默认没有预装Chrome或Chromium,打开Replit的Shell,执行以下命令完成安装:

apt-get update && apt-get install -y chromium-browser

步骤2:修改Eel代码,指定浏览器路径与无头模式

你的原代码存在语法错误:eel.expose需要以装饰器形式使用(添加@符号),同时要指定Chromium的路径并启用无头模式(Replit无图形桌面环境,必须用无头模式运行浏览器),修改后的完整代码如下:

import eel

eel.init('web')

# 正确使用@eel.expose装饰器暴露Python函数给前端
@eel.expose
def Something():
    return "hhaa tf"

# 指定Chromium路径,配置无头运行参数
chrome_path = '/usr/bin/chromium-browser'
eel.start(
    "index.html",
    mode='custom',
    cmd_args=[
        chrome_path,
        '--headless',
        '--disable-gpu',
        '--no-sandbox',
        '--remote-debugging-port=9222',
        '--window-size=800,600',
        '%s'
    ]
)

补充:确保web文件夹与index.html存在

如果还未创建相关文件,需在项目根目录下新建web文件夹,在其中创建index.html文件,示例内容如下:

<!DOCTYPE html>
<html>
<body>
    <h1>Eel 测试页面</h1>
    <button onclick="eel.Something()().then(res => alert(res))">调用Python函数</button>
    <script type="text/javascript" src="/eel.js"></script>
</body>
</html>

内容的提问来源于stack exchange,提问作者user19222567

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 22:30:33