A new tab doesn't open up in my web-browser if I run the streamlit-python script

I just installed Streamlit. I wrote a hello world program. But no new tab opened in my browser, so I couldn’t see the result of my program.

1 Like

HI @p0l4r! Welcome to the community. :slight_smile:

I’m sorry you had trouble seeing your app. So that I can help you better, could you please share the following information with me:

  1. Are you running this example on a local machine (e.g. your laptop) or a remote machine (e.g. an Amazon EC2 instance)?
  2. Does the same behavior occur when you run streamlit hello rather than your own script?
  3. Have you tried manually going the addresses displayed when you launch Streamlit? For example, when I see:
$ streamlit hello

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://192.168.1.51:8501

so you would point your browser to http://localhost:8501.

  1. What browser and operating system are you using?

Thanks!

  1. I am running the example on my personal computer ( local machine ).
  2. I ran streamlit hello.
  3. I have tried that. Didn’t work.
  4. I am using Windows 10 as OS and Google Chrome as web browser.

That’s super strange.

To debug, I would like to see if the Python package we use to open the browser is working on your system. Can you try the command below in a Python interpreter (using the same environment you use for Streamlit):

import webbrowser
webbrowser.open('http://streamlit.io')

And just for completeness, can you tell us what this prints out:

import platform
platform.system()
1 Like
  1. when I used-
    import webbrowser
    webbrowser.open(‘http://streamlit.io’)

A new tab opened in my browser and I got redirected to http://streamlit.io

  1. when I used-
    import platform
    platform.system()

This happened

Great, so we can eliminate that hypothesis :smiley:

Oh, I forgot to ask: can you try printing the output of platform.system() to the console?

Here it is
image

That’s very strange. What Streamlit does is just combine those two commands like this:

if platform.system() == 'Windows':
  webbrowser.open(streamlit_url)

So if that’s not working, I’m at a loss…

Actually, re-reading the thread I see you said that manually going the address displayed when you launch Streamlit doesn’t work. This makes me think the Windows Firewall may be blocking Streamlit.

Can you look at the Firewall settings and see if Streamlit is allowed to access port 8501?

Can you please tell me how I do that ? I have tried different method, allowed streamlit application through firewall , but it is not working. I think I am not doing it right.

Hi @p0l4r,

Sorry for the delay. I’ve been on-and-off trying to find some docs on how to do that, but could not find anything that looked promising. (Did I mention I’m not a Windows user? :wink:)

So I have a couple more questions to help debug:

  1. When you run python -m http.server 8000 and go to http://localhost:8000 on your browser, does it show a file listing? This will tell me whether the problem is Streamlit-specific or related to any server running on your machine.

    (After you try the above, press Ctrl-C on the terminal)

  2. Try streamlit hello and then run this on another terminal: netstat -an | find "8501"

    If you see something that says “LISTENING” that means Streamlit started correctly. For example:

    TCP    0.0.0.0:8501           0.0.0.0:0              LISTENING
    
  3. Try streamlit hello then open 127.0.0.1:8501 on your browser. Does that work? If so, this command should make localhost work too: netsh http add iplisten 127.0.0.1

This is what happens.

  1. After running streamlit hello I tried the command netstat -an | find “8501”. It showed nothing.

  2. No it does not work.

That’s strange. So just to make 100% sure, can you confirm that these are the steps you took:

  1. Open a terminal and a Python environment where Streamlit is installed.
  2. Run streamlit hello
  3. Open another terminal
  4. Run netstat -an | find "8501"

Dear Sir, I tried running streamlit hello, but nothing happened. Then I tried to run a longer script, still same.

Install Python 3.7.5 it’s a perfect solution for Windows Users

Hey @p0l4r

Thanks for the screenshot — that actually clarifies things.

It looks like you’re running your Streamlit app st.py straight from a Python console. That’s not how you’re supposed to run those.

Instead you should call streamlit run like this in a terminal:

streamlit run st

I hope that helps!

I usually use the python IDLE. I also tend to run from the IDLE by pressing the F5. My usual way of running python script didn’t work. Can you please tell me how to run this from terminal ? I tried once, but didn’t work from terminal. My file is in the J:/ drive , in st folder.

Can you please give the exact command or way to run the code from the terminal ?

And , I have checked, streamlit is installed.
image

Hey @p0l4r

I think the problem is that Streamlit is being installed in a Python environment that is not accessible from the Windows terminal. To solve this I’d have to know exactly how you installed Python, which on Windows could be in a thousand different ways — and I’m definitely not an expert in every single one of them :laughing:

On Windows, my preferred way to use Python is with Anaconda. It makes it super easy to create new Python environments, manage them, install packages, open a terminal pointing to the right environment, and so on.

Here are the installation instructions for that: https://docs.anaconda.com/anaconda/install/windows/

Once that’s installed, you can open the Anaconda Navigator, create a new environment, install Streamlit in there, and then do this to open a terminal where Streamlit will work:

image
(in the screenshot above my environment is called “Orange” for some reason! Yours can be named whatever you want)

1 Like

I installed streamlit using pip. What should one do for pip ? Just wanted to know for future reference.