Before diving into Streamlit development, it's crucial to set up a proper Python environment. This ensures smooth development, dependency management, and project isolation. Let's walk through the process step-by-step.
First things first, you need Python installed on your system. Streamlit supports Python 3.7 and above.
To verify the installation, open a terminal and type:
python --version
You should see the Python version displayed.
Virtual environments are isolated Python environments that allow you to manage project-specific dependencies. This is especially useful when working on multiple projects with different requirements.
python -m venv streamlit_env
streamlit_env\Scripts\activate
source streamlit_env/bin/activate
If you prefer using Conda:
conda create --name streamlit_env python=3.9
conda activate streamlit_env
With your virtual environment activated, install Streamlit using pip:
pip install streamlit
To verify the installation:
streamlit hello
This should launch a demo Streamlit app in your default web browser.
A good Integrated Development Environment (IDE) can significantly boost your productivity. Here are some popular options:
Visual Studio Code (VS Code): Free, lightweight, and highly customizable with a rich extension ecosystem.
PyCharm: A powerful IDE specifically designed for Python development, with both free and paid versions available.
Jupyter Notebooks: Great for data analysis and experimentation, especially when combined with Streamlit's support for Jupyter widgets.
For this guide, let's focus on setting up VS Code, as it's free and widely used.
Ctrl+Shift+P
(or Cmd+Shift+P
on macOS)Let's create a simple Streamlit app to test our setup:
app.py
import streamlit as st st.title("Hello, Streamlit!") st.write("Welcome to your first Streamlit app.") number = st.slider("Select a number", 0, 100) st.write(f"You selected: {number}")
streamlit run app.py
Your default web browser should open, displaying your first Streamlit app!
As your project grows, you'll likely add more dependencies. Keep track of them using a requirements.txt
file:
requirements.txt
file in your project rootstreamlit
pandas
matplotlib
pip install -r requirements.txt
This makes it easy to recreate your environment on other machines or for collaboration.
Version control is crucial for any development project. Here's how to set up Git for your Streamlit project:
git init
.gitignore
file to exclude unnecessary files:# .gitignore
streamlit_env/
__pycache__/
*.pyc
git add . git commit -m "Initial commit"
With these steps completed, you've successfully set up a robust development environment for your Streamlit projects. Happy coding!
06/12/2024 | Python
06/10/2024 | Python
21/09/2024 | Python
08/11/2024 | Python
22/11/2024 | Python
15/11/2024 | Python
06/10/2024 | Python
15/10/2024 | Python
25/09/2024 | Python
15/11/2024 | Python
25/09/2024 | Python
05/11/2024 | Python