Open In App

Streamlit – Complete Setup Guide

Last Updated : 14 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Streamlit is an open-source app framework in python language. It helps us create beautiful web apps for data science and machine learning in a little time. It is compatible with major python libraries such as scikit-learn, keras, PyTorch, latex, numpy, pandas, matplotlib, etc. Syntax for installing this library is shown below. 

Install StreamLit :

Before you get started, there’re a few things you’re going to need :

1. Download an IDE or text editor
2. Install Python in your system (preferably Python 3.7 – Python 3.10)
3. Install PIP in your system.

Set up your virtual environment

First of all we need to setup a virtual environment  to run few commands. This will ensure that the dependencies installed/updated for Streamlit will not impact any other Python projects on the system. Tools that you can use for environment management: pipenv, poetry, venv, virtualenv, conda.

Anaconda Navigator is Streamlit’s officially-supported environment manager on Windows, hence we need to download that.

Install Anaconda

If you don’t have Anaconda install yet, follow this article to install it – how-to-install-anaconda-on-windows.

Create a new environment with Streamlit

Now we will be setting up the environment.

  • Anaconda provides steps for setting up Anaconda and managing the environment through the Anaconda Navigator. Follow them and setup Anaconda.
  • Next, select the “▶” icon appearing next to your new environment. Then we need to select “Open terminal” from the menu that appears.

Anaconda Navigator

  • In the command-prompt type
pip install streamlit

Installing streamlit

  • Now, test that the installation worked using the command-
streamlit hello

Testing installation

Creating a Simple application (Hello World) – 

The 'hello, world!' script in Streamlit:
streamlit hello

# to run your python script
streamlit run myFirstStreamlitApp.py

You can stop running your app any time using Ctrl + C

Check the Streamlit Version using Terminal

Open the terminal and write the command in your terminal:

streamlit --version

This command should tell you what version the installed streamlit package is.

Checking version of Streamlit via terminal

Check the Streamlit Version using the pip

Using the pip command gives all the detail of current versions of python modules which you installed in your system.

To check Streamlit version,open your terminal and write the pip command in your terminal. If Streamlit is not currently installed in your system, it will not appear in the list of modules.

pip freeze

Checking version of Streamlit via pip

Update Streamlit Version

If you want to update your Streamlit version you can use any one of these commands to update your Streamlit.

python -m pip install --upgrade Streamlit

Updating Streamlit version

Streamlit updating

python -m pip install -U Streamlit

Updating version of Streamlit

This will update your Streamlit to the latest version.

Advantages of Streamlit :

1. It embraces python-scripting. 
2. Less code is needed to create amazing web-apps. 
3. No callbacks are needed since widgets are treated as variables. 
4. Data caching simplifies and speeds up computation pipelines. 

Disadvantages of Streamlit :

1. Streamlit’s Data caching cannot keep track of changes to the data happening outside the function body. 

Some of its basic functions are described here. 

1. Adding a Title 

Python3




# myFirstStreamlitApp.py
 
# import the library
import streamlit as stl
 
# add title to your app
stl.title("Geeks for Geeks")


Output: 
 

2. Adding some text 

Python3




# myFirstStreamlitApp.py
 
# import the library
import streamlit as stl
 
# add title to your app
stl.title("Geeks for Geeks")
 
# adding text to your app
stl.write("A Computer Science portal for Geeks")


Output: 
 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads