0

I was trying to deploy my web app on Heroku and I was using the webbrowser module to open a link when a button is clicked but the deployment failed with this error:

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

Here is the requirements.txt file:

joblib>=0.14.0
numpy>=1.9.2
matplotlib>=1.4.3
pandas>=0.19
streamlit
scikit-learn==0.22.1
webbrowser

And here is how I use webbrowser:

import webbrowser

webbrowser.open('URL')

When I deployed the app without mentioning webbrowser in the requirements.txt file the app was deployed successfully but the feature of opening the URL when the button is clicked was not working.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • How do you use `webbrowser` in your code? What do you expect to happen on Heroku? Normally, this [would run an actual web browser](https://docs.python.org/library/webbrowser.html#module-webbrowser), but popping a window up on some server in some AWS data centre doesn't make much sense. (Note that `webbrowser` is a built-in module—you don't need to install it via `requirements.txt`. That might fix your build error, but the previous question remains.) – ChrisGPT was on strike Jul 09 '20 at 22:42
  • `import webbrowser` `webbrowser.open('URL')` this is how I was using web-browser to open the URL.i created a button and when it is clicked it is supposed to open the URL. when I didn't mention the web-browser module in `requirements.txt` the feature was not working. – Siddhant Ranjan Jul 10 '20 at 06:13

1 Answers1

1

The webbrowser module is part of Python's standard library. You don't need to (and can't) install it via pip, so it doesn't belong in your requirements.txt. Take it back out.

Now that your deployment is working, we need to fix the real problem: you can't open a browser with webbrowser on Heroku. Python code runs on the server, not the client. If this does anything it will open a browser on a machine somewhere in an AWS data centre, not on the client machine.

I'm not sure how you've connected your button to the back-end, but JavaScript can open windows on the client side.

Be careful doing this, as pop-ups have a very bad reputation and users generally don't like them. Furthermore, many browsers have protection against this now; your users will probably have to approve the pop-up. I strongly recommend finding another solution that doesn't involve creating new browser windows.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257