Streamlit hello results in 404 error in bespoke environment

:rotating_light: Before clicking “Create Topic”, please make sure your post includes the following information (otherwise, the post will be locked). :rotating_light:

  1. Are you running your app locally or is it deployed?
    I installed streamlit on my laptop to see if I can use it. But we don’t use environments so I saved it to …/r/pylib
    I run it like …/r/pylib/bin/streamlit hello from the r directory. First the normal streamlit next to the streamlit.cmd couldn’t find itself, so I had to add the path to streamlit
with sys.path.extend([
    str(Path(__file__).parent.joinpath('pylib')),
    str(project_path)
    ])

but there’s probably more hocus pocus that I couldn’t find in the docs because normal people just make an environment and call it a day. I did install with pip
2. If your app is deployed:
It’s the hello app that comes from streamlit
3. Share the link to your app’s public GitHub repository
Maybe na?
4. Share the full text of the error message (not a screenshot).
2024-01-13 15:11:00.717 WARNING tornado.access: 404 GET / (::1) 0.92ms on the server and
404: Not Found in the browser. I didn’t go to localhost:3000 like the server suggested. I went to 8501 otherwise the connection was refused. Also, other servers like jupyter notebooks works, so I dont’ think its a firewall issue
5. Share the Streamlit and Python versions.
For this feat, I just ran my app without streamlit and with the path augmented. streamlit imported and print(streamlit.version) yielded 1.30.0. Who knows if that’s what’s running
python is 3.10.13
Here’s what my server says

~/.../pupu-platter/russell(main*)$  ./pylib/bin/streamlit hello
2024-01-13 15:10:45.708 WARNING streamlit.config: 
Warning: the config option 'server.enableCORS=false' is not compatible with 'server.enableXsrfProtection=true'.
As a result, 'server.enableCORS' is being overridden to 'true'.

More information:
In order to protect against CSRF attacks, we send a cookie with each request.
To do so, we must specify allowable origins, which places a restriction on
cross-origin resource sharing.

If cross origin resource sharing is required, please disable server.enableXsrfProtection.
            
2024-01-13 15:10:45.815 DEBUG   streamlit.web.server.server: Starting server...
2024-01-13 15:10:45.815 DEBUG   streamlit.web.server.server: Serving static content from the Node dev server
2024-01-13 15:10:45.822 DEBUG   streamlit.web.server.server: Server started on port 8501
2024-01-13 15:10:45.822 DEBUG   streamlit.runtime.runtime: Runtime state: RuntimeState.INITIAL -> RuntimeState.NO_SESSIONS_CONNECTED

  Welcome to Streamlit. Check out our demo in your browser.

  Local URL: http://localhost:3000
  Network URL: http://17.198.35.92:3000

  Ready to create your own Python apps super quickly?
  Head over to https://docs.streamlit.io

  May you create awesome apps!


  For better performance, install the Watchdog module:

  $ xcode-select --install
  $ pip install watchdog
            
2024-01-13 15:10:46.071 DEBUG   streamlit.web.bootstrap: Setting up signal handler
2024-01-13 15:11:00.717 WARNING tornado.access: 404 GET / (::1) 0.92ms
^C  Stopping...
2024-01-13 15:32:41.187 DEBUG   streamlit.runtime.runtime: Runtime stopping...
2024-01-13 15:32:41.188 DEBUG   streamlit.runtime.runtime: Runtime state: RuntimeState.NO_SESSIONS_CONNECTED -> RuntimeState.STOPPING
2024-01-13 15:32:41.188 DEBUG   streamlit.runtime.runtime: Runtime state: RuntimeState.STOPPING -> RuntimeState.STOPPED

This is a bit confusing but it looks like you didn’t install streamlit properly.

Yes, I agree. I installed it with the target flag. Python -pip install streamlit --target /r/pylib. I thought streamlit would be able to handle it but maybe more steps are needed in an environment variable somewhere

Using --target can require changes to PYTHONPATH or sys.path, which can have unintended effects and make your installation harder to maintain. Virtual environments will take care of such issues for you, I don’t think you have any reason to avoid them.

The only reason why I avoid them is because I can’t convince my behemoth of a company to use them because they have their own methodology. If stream lit has to be run without the --target flag in a special environment, that’s too bad. Dash doesn’t.

So you have a policy that forbids running python -m venv in your computer, but it allows you to mess with environment variables and pip flags that are known to cause a lot of trouble? And they are monitoring what commands you run as a user? That is really bad.

How about just pip install streamlit, then?

Anyway, it is not clear to me that your issues arise from that. I find your description of what you did and what happened quite confusing, but there are things that doesn’t look right.

I run it like …/r/pylib/bin/streamlit hello from the r directory.

I may be better if you add that to the PATH environment variable. Or just do python -m streamlit hello.

First the normal streamlit next to the streamlit.cmd couldn’t find itself,

I have no idea what that means, I guess you were greeted with some kind of “file not found” message, but that doesn’t really tell much.

so I had to add the path to streamlit

You patched streamlit? That is almost definitely wrong. Add it to the PYTHONPATH environment variable instead.

For this feat, I just ran my app without streamlit and with the path augmented. streamlit imported and print(streamlit.version) yielded 1.30.0. Who knows if that’s what’s running

You are calling streamlit to run the hello application. why don’t you call it in the same way to get the version? Like ./pylib/bin/streamlit version or whatever you are using to run streamlit.

Warning: the config option 'server.enableCORS=false'

Looks like you messed with the configuration? Don’t do that. You don’t want to be distracted by irrelevant warnings, or worse, accidentally break something while you are trying to solve a different problem.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.