Now I have updated streamlit to version 1.5 and it does not work anymore:
File "/some/path/python3.8/site-packages/streamlit/cli.py", line 214, in _get_command_line_as_string
assert parent.command_path == "streamlit"
AssertionError
Is there a quick fix or is this way of running streamlit not supported anymore, as the assertion now requires that streamlit is run from the streamlit executable?
This is a bit of a fun story. We actually didn’t realize there was a pretty large group of people (mostly PyCharm and VSCode users) running streamlit via python -m streamlit.cli <command>. This method was discovered by the community and seems to have spread through the StackOverflow post that you linked, but internally we never really considered it a “supported” method (it’s undocumented so isn’t considered part of our public API. It just so happens that you used to be able to run the submodule to get functionality equivalent to using streamlit run <command>).
A very similar and equivalent way of invoking streamlit that is supported (so has guarantees to not be broken in the future) is to simply run:
python -m streamlit <command>
instead. Alternatively, another way of running streamlit from PyCharm is described here: Version 1.5.0 - #11 by tim
We’re discussing this internally since it is unfortunate that we inadvertently broke some people’s dev envs, and while a decision hasn’t been finalized, it sounds like we’ll likely keep things as-is (but improve the error message / add official documentation for setting up Streamlit with PyCharm/VSCode) since
it feels a bit weird adding official support for a way of invoking streamlit that we never intended to officially support (my guess is that that particular file is only runnable because it made it easier to build/debug when streamlit was first being built, and we just forgot to remove those lines)
it’s not too much effort to just remove the .cli so that streamlit is now being started using a supported method
Hi @vdonato,
Great answer, I really appreciate your effort!
I just tried your solution of removing the .cli and it works like a (py)charm !
Cheers
Oliver
I’ve been trying for the last few hours to debug my streamlit application using the methods described in this thread and the various linked threads but have not been able to get it working. The app runs fine using the streamlit run command.
My environment:
Windows 10
Anaconda
PyCharm
python 3.10.13
streamlit 1.26.0
Here is my configuration which, based on reading these threads, seems to be the recommended approach:
I managed to solve the issue! One of the folders in my project was named “streamlit” which seemed to be causing conflict issues with the actual streamlit module.
Hi @vdonato
I am trying to run streamlit in PyCharm 2023.3.4 Professional like you describe, and am getting the below error.
Any suggestions on how to fix that?
Exception in callback <Task pending name='Task-1' coro=<run.<locals>.run_server() running at C:\Users\egor.kraev\AppData\Local\miniconda3\envs\llm3.11\Lib\site-packages\streamlit\web\bootstrap.py:391> cb=[_run_until_complete_cb() at C:\Users\egor.kraev\AppData\Local\miniconda3\envs\llm3.11\Lib\asyncio\base_events.py:180]>()
handle: <Handle <Task pending name='Task-1' coro=<run.<locals>.run_server() running at C:\Users\egor.kraev\AppData\Local\miniconda3\envs\llm3.11\Lib\site-packages\streamlit\web\bootstrap.py:391> cb=[_run_until_complete_cb() at C:\Users\egor.kraev\AppData\Local\miniconda3\envs\llm3.11\Lib\asyncio\base_events.py:180]>()>
Traceback (most recent call last):
File "C:\Users\egor.kraev\AppData\Local\miniconda3\envs\llm3.11\Lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
TypeError: 'Task' object is not callable
If false, will attempt to open a browser window on start.
Default: false unless (1) we are on a Linux box where DISPLAY is unset, or
(2) we are running in the Streamlit Atom plugin.
headless = false
Automatically rerun script when the file is modified on disk.
Default: false
runOnSave = false
The address where the server will listen for client and browser
connections. Use this if you want to bind the server to a specific address.
If set, the server will only be accessible from this address, and not from
any aliases (like localhost).
Default: (unset)
address =
The port where the server will listen for browser connections.
Don’t use port 3000 which is reserved for internal development.
Default: 8501
port = 8501
The base path for the URL where Streamlit should be served from.
Default: “”
baseUrlPath = “”
Enables support for Cross-Origin Resource Sharing (CORS) protection, for added security.
Due to conflicts between CORS and XSRF, if server.enableXsrfProtection is on and
server.enableCORS is off at the same time, we will prioritize server.enableXsrfProtection.
Default: true
enableCORS = true
Enables support for Cross-Site Request Forgery (XSRF) protection, for added security.
Due to conflicts between CORS and XSRF, if server.enableXsrfProtection is on and
server.enableCORS is off at the same time, we will prioritize server.enableXsrfProtection.
Default: true
enableXsrfProtection = true
Max size, in megabytes, for files uploaded with the file_uploader.
Default: 200
maxUploadSize = 200
Max size, in megabytes, of messages that can be sent via the WebSocket connection.
Default: 200
maxMessageSize = 200
Enables support for websocket compression.
Default: false
enableWebsocketCompression = false
Enable serving files from a static directory in the running app’s directory.
Default: false
enableStaticServing = false
Server certificate file for connecting via HTTPS.
Must be set at the same time as “server.sslKeyFile”.
[‘DO NOT USE THIS OPTION IN A PRODUCTION ENVIRONMENT. It has not gone through security audits or performance tests. For the production environment, we recommend performing SSL termination by the load balancer or the reverse proxy.’]
sslCertFile =
Cryptographic key file for connecting via HTTPS.
Must be set at the same time as “server.sslCertFile”.
[‘DO NOT USE THIS OPTION IN A PRODUCTION ENVIRONMENT. It has not gone through security audits or performance tests. For the production environment, we recommend performing SSL termination by the load balancer or the reverse proxy.’]
sslKeyFile =
[browser]
Internet address where users should point their browsers in order to
connect to the app. Can be IP address or DNS name and path.
This is used to:
- Set the correct URL for CORS and XSRF protection purposes.
- Show the URL on the terminal
- Open the browser
Default: “localhost”
serverAddress = “localhost”
Whether to send usage statistics to Streamlit.
Default: true
gatherUsageStats = true
Port where users should point their browsers in order to connect to the
app.
This is used to:
- Set the correct URL for XSRF protection purposes.
- Show the URL on the terminal (part of streamlit run).
- Open the browser automatically (part of streamlit run).
This option is for advanced use cases. To change the port of your app, use
server.Port instead. Don’t use port 3000 which is reserved for internal
development.
Default: whatever value is set in server.port.
serverPort = 8501
[mapbox]
Configure Streamlit to use a custom Mapbox
token for elements like st.pydeck_chart and st.map.
import streamlit as st
# Define a callback function
def my_callback():
st.sidebar.write("settings clicked!")
st.title("Complex Layout Example")
# Sidebar for navigation
st.sidebar.header("Navigation")
st.sidebar.button("Home")
if st.sidebar.button("Settings"):
my_callback()
# Main content with columns and expander
col1, col2 = st.columns([2, 1])
with col1:
st.header("Main Content")
with st.expander("More Information"):
st.write("Additional details can go here")
st.button("Expander Button")
with col2:
st.header("Sidebar Content")
st.button("Sidebar Button")
# Additional content in a container
with st.container():
st.header("Footer Section")
st.write("Footer content goes here")
The key that worked for me is to create another module called run.py
try:
# for streamlit >= 1.12.1
from streamlit.web import bootstrap
except ImportError:
from streamlit import bootstrap
real_script = 'main.py'
bootstrap.run(real_script, False, [f'run.py {real_script}'], {})
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.