我试图在Heroku上部署我的Web应用程序,并且我使用webbrowser
模块来打开链接,但是当单击按钮但部署失败时出现此错误:
ERROR: Could not find a version that satisfies the requirement webbrowser (from -r/tmp/build_1a0f381f625ed056f039e4b30415d590/requirements.txt (line 7))
(from versions: none)
ERROR: No matching distribution found for webbrowser (from -r /tmp/build_1a0f381f625ed056f039e4b30415d590/requirements.txt (line 7))
! Push rejected, failed to compile Python app.
! Push failed
这是requirements.txt
文件:
joblib>=0.14.0
numpy>=1.9.2
matplotlib>=1.4.3
pandas>=0.19
streamlit
scikit-learn==0.22.1
webbrowser
这是我使用webbrowser
的方式:
import webbrowser
webbrowser.open('URL')
当我在webbrowser
文件中未提及requirements.txt
的情况下部署该应用程序时,该应用程序已成功部署,但是单击按钮时打开URL的功能不起作用。
答案 0 :(得分:1)
The webbrowser
module is part of Python's standard library。您不需要通过pip
安装(并且不能),因此它不属于您的requirements.txt
。拿回来。
现在您的部署正在运行,我们需要解决一个实际问题:您无法在Heroku上使用webbrowser
打开浏览器。 Python代码在服务器而不是客户端上运行。如果这样做,它将在AWS数据中心某处的计算机上打开浏览器,而不是在客户端计算机上打开浏览器。
我不确定您如何将按钮连接到后端,但是JavaScript can open windows on the client side。
请谨慎操作,因为弹出式窗口的声誉非常差,用户通常不喜欢它们。而且,许多浏览器现在都可以防止这种情况的发生。您的用户可能需要批准弹出窗口。我强烈建议找到另一种不涉及创建新浏览器窗口的解决方案。