Clone, Install and Run Streamlit App [Step-by-Step Guide]

If you want to try Streamlit but don’t know how to set it up, this guide is for you! Streamlit helps you create interactive web apps with Python easily. We’ll show you how to set it up step by step—cloning a project, installing what you need, and running your first app. Let’s get started!

What is Streamlit?

Streamlit is a free and open-source Python tool. It allows data scientists and developers to build web apps quickly. It’s widely used because it saves time and reduces effort. You don’t need to know complex coding like HTML, CSS, or JavaScript. Instead, Streamlit makes it easy to create interactive pages with just Python. With Streamlit, you can turn your Python code into web apps that anyone can use. It’s great for showing data, creating dashboards, or building tools. Additionally, you only need a few lines of code to get started. It’s perfect for beginners who want to share their work simply.

Why Use Streamlit?

Here are a few reasons why Streamlit is a favorite among beginners and developers:

  • Easy to use: You can build interactive features like buttons, sliders, and graphs with just a few lines of Python code. There’s no need to learn complex web development tools like HTML or JavaScript, making it beginner-friendly.
  • Great for data work: Streamlit is designed for data science and machine learning projects. It makes it simple to display data tables, charts, and even model predictions directly in a web app, so you can share your results easily.
  • Instant updates: When you make changes to your code, the app refreshes right away. This means you can see the updates in real time without needing to restart the app, making the testing process much quicker.
  • Free and open for all: Streamlit is completely free to use and is open-source, meaning anyone can contribute to its improvement. It’s always being updated with new features, so you’ll have access to the latest tools as they become available.

Prerequisites

Before we start, make sure the following software is installed on your machine:

  1. Python: Streamlit requires Python 3.7 or higher.
    To check if you have Python installed, run: python --version
  2. Git: Git is necessary to clone repositories from GitHub.
    To check if you have Git installed, run: git --version
  3. PIP: Ensure that pip, Python’s package installer, is available.
    To check if you have pip installed, run: pip --version

Step 1: Clone the Streamlit Project from GitHub

GitHub is a website where developers share their code. We’ll use it to download a Streamlit app. Open the Command Prompt (Windows) or Terminal (Mac/Linux).

What does Cloning mean?

When we say clone a repository, it means copying the entire code (project) from someone’s GitHub repository (repo) onto your computer. This way, you can edit and run the project locally.

1: Choose a Folder to Download the Project

You need to decide where on your computer you want to store the project. You can move to that folder using the cd command (which means change directory).

Example:

This command changes your working directory to the Desktop.

cd Desktop

2: Find the GitHub Repository URL

  • Go to GitHub in your web browser.
  • Navigate to the repository (project) you want to clone.
  • Click the Code button (it’s a green button near the top-right corner of the page).
  • You’ll see a URL (something like https://github.com/streamlit/example-app-ab-testing.git). This is the link you need to copy. It tells Git which project to download.
Copy streamlit Project link from github using command line
Copying project from GitHub

3: Clone the Repository Using Git

Once you have the repository URL copied, switch back to your Terminal/Command Prompt. Now, type the following command to download the project:

Example:

  • git is the command to use Git (the tool we checked earlier).
  • clone tells Git to copy the project.
  • The URL (in this case, https://github.com/streamlit/example-app-ab-testing.git) tells Git which project to copy.
  • When you press Enter, Git will download the entire project to your current folder.
git clone https://github.com/streamlit/example-app-ab-testing.git

Cloning a streamlit project from github
Cloning Project

4: Check If the Project is Downloaded

After the cloning is complete, Git will create a new folder inside the directory where you ran the git clone command. This folder will have the same name as the project (in our case, example-app-ab-testing).

Example:

  • cd means “change directory.”
  • We are changing into the new folder, example-app-ab-testing, where the project files are stored.
  • Now you are inside the project folder and ready to work with the code.
cd example-app-ab-testing

streamlit app folder
Streamlit app folder
streamlit app files
Streamlit Project Files

Step 2: Create and Activate a Virtual Environment

When working on a Python project (like a Streamlit app), it’s a good idea to use a virtual environment. This ensures that all the required Python packages and libraries for the project are kept separate from other projects on your computer. Think of a virtual environment as a “box” that contains only the specific tools your project needs, so your project doesn’t accidentally use conflicting or outdated packages from your system.

1: Create a Virtual Environment

Type the following command in your terminal to create a virtual environment:

Example:

  • python or python3: This runs the Python interpreter.
  • -m venv: This directs Python to set up a virtual environment.
  • venv: This is the name of the virtual environment folder (you can name it something else if you want).

After running the command, a new folder called venv will appear inside your project folder. This folder contains everything your virtual environment needs.

Windows:

python -m venv venv

Mac/Linux:

python3 -m venv venv

2: Activate the Virtual Environment

Let’s activate the virtual environment to install libraries (like Streamlit) inside it.

Windows:

venv\Scripts\activate

Mac/Linux:

source venv/bin/activate

How to Check if the Virtual Environment Is Activated?

Once the virtual environment is activated, you’ll see (venv) at the beginning of your terminal prompt. Any packages you install now will be added only inside the virtual environment, and they won’t affect the rest of your system.

(venv) C:\Users\YourName\example-app-ab-testing>

Step 4: Install Streamlit and Other Dependencies

Once your virtual environment is activated, the next step is to install the necessary tools to run your Streamlit app. This step ensures your project has all the required libraries (dependencies) to function smoothly. Think of dependencies as ingredients needed to make a recipe. In this case, Streamlit is the main ingredient, and some other optional libraries may also be required for your specific app.

1: Install Streamlit

Streamlit is the main tool we need to run the app. To install it, type the following command:

pip install streamlit

2: Install Other Dependencies from requirements.txt

Sometimes, the project you cloned might need other libraries to work. These libraries are listed in a special file called requirements.txt. If this file is in your project folder, it’s easy to install everything in one go. To install the dependencies listed in requirements.txt, run:

pip install -r requirements.txt

Step 5: Run the Streamlit App

Now that you’ve set up your virtual environment and installed Streamlit and any other required dependencies, it’s time to run the app. This is the exciting part where you’ll see the Streamlit app directly in your web browser!

  • streamlit: This command starts the Streamlit tool.
  • run: Tells Streamlit to execute the app.
  • app.py: This is the Python script that contains the Streamlit code (replace app.py with the name of your main app file if it’s different).
streamlit run example-app-ab-testing.py

Testing of streamlit app using command line
Running a Streamlit app

Conclusion

In this guide, you have learned how to clone a Streamlit project, set up a virtual environment, install the required libraries, and run the app on your computer. By following these steps, you can easily work on Python projects without worrying about conflicts and start building interactive web apps with Streamlit. This setup helps you focus on coding and exploring, making it a great way to visualize data and create user-friendly apps.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top