Knowledgebase

How to Install Streamlit on Debian 10 Print

  • 0

Introduction

Streamlit is an open-source python library designed to create custom web applications for machine learning and data science. It is one of the fastest ways to design, build, and deploy data applications. This article explains how to run a Streamlit-based web application on a Debian 10 Server.

1. Install Prerequisites

Update Python

The default Debian repositories contain Python 3.7 only, so we will use Python source code to install the latest python 3.

  1. Install the required dependencies to compile the Python source code.

     # apt-get install wget build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev liblzma-dev -y
  2. Download the latest Python3 source code.

     # wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
  3. Extract the downloaded python source code archive.

     # tar xzf Python-3.9.6.tgz
  4. Compile the python source code.

     # cd Python-3.9.6 && ./configure --enable-optimizations
  5. Install Python 3.9.6.

     # make altinstall
  6. Set Python 3.9.6 as default version.

     # update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1
  7. Update pip.

     # /usr/local/bin/python3.9 -m pip install --upgrade pip
  8. Set pip from Python 3.9.6 as default version.

     # update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.9 1
  9. Check the current version of Python and pip.

     # python --version && pip --version
  10. Change to root directory.

     # cd

2. Install Streamlit

Install Streamlit using Python pip.

# pip install streamlit

3. Run Streamlit on Debian 10

Option 1: Use the Default Port

Streamlit runs on port 8501 by default, so you need to allow port 8501 on firewall.

# ufw allow 8501

When you run Streamlit on a normal SSH Session, the Streamlit process will close once you exit the SSH Session. To run Streamlit when you leave the SSH session, use tmux, a terminal multiplexer. Using a terminal multiplexer will allow you to run the Streamlit process in the background. To create a tmux session, run:

# tmux new -s StreamlitSession

You can change StreamlitSession to any session name you prefer. Please see How to Install and Use Tmux for more information.

Once you are on the Terminal Multiplexer, you can now run your main python script. Make sure that your python script is in the /root/ directory, then run:

# streamlit run main.py

Change main.py to your python script file name.

When you run Streamlit for the first time, you will be prompted to enter your email address. If you want to receive Streamlit updates, kindly enter your email address, or you can press Enter to skip it.

To view your deployed web application, visit http://server_ipaddress:8501

Option 2: Run Streamlit on HTTP Port

To deploy your web application on HTTP Port (80), allow http port (80) on the firewall first. Run:

# ufw allow 80

then run:

# streamlit run main.py --server.port 80

Change main.py to your python script file name.

To view your deployed web application, visit http://server_ipaddress

Troubleshooting

If you have encountered some issues or want to learn more, please visit the Streamlit documentation.

Introduction Streamlit is an open-source python library designed to create custom web applications for machine learning and data science. It is one of the fastest ways to design, build, and deploy data applications. This article explains how to run a Streamlit-based web application on a Debian 10 Server. 1. Install Prerequisites Deploy a Rcs Debian 10 VPS Instance. Login as root. Update the Debian Server. Update Python The default Debian repositories contain Python 3.7 only, so we will use Python source code to install the latest python 3. Install the required dependencies to compile the Python source code. # apt-get install wget build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev liblzma-dev -y Download the latest Python3 source code. # wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz Extract the downloaded python source code archive. # tar xzf Python-3.9.6.tgz Compile the python source code. # cd Python-3.9.6 && ./configure --enable-optimizations Install Python 3.9.6. # make altinstall Set Python 3.9.6 as default version. # update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1 Update pip. # /usr/local/bin/python3.9 -m pip install --upgrade pip Set pip from Python 3.9.6 as default version. # update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.9 1 Check the current version of Python and pip. # python --version && pip --version Change to root directory. # cd 2. Install Streamlit Install Streamlit using Python pip. # pip install streamlit 3. Run Streamlit on Debian 10 Option 1: Use the Default Port Streamlit runs on port 8501 by default, so you need to allow port 8501 on firewall. # ufw allow 8501 When you run Streamlit on a normal SSH Session, the Streamlit process will close once you exit the SSH Session. To run Streamlit when you leave the SSH session, use tmux, a terminal multiplexer. Using a terminal multiplexer will allow you to run the Streamlit process in the background. To create a tmux session, run: # tmux new -s StreamlitSession You can change StreamlitSession to any session name you prefer. Please see How to Install and Use Tmux for more information. Once you are on the Terminal Multiplexer, you can now run your main python script. Make sure that your python script is in the /root/ directory, then run: # streamlit run main.py Change main.py to your python script file name. When you run Streamlit for the first time, you will be prompted to enter your email address. If you want to receive Streamlit updates, kindly enter your email address, or you can press ENTER to skip it. To view your deployed web application, visit http://server_ipaddress:8501 Option 2: Run Streamlit on HTTP Port To deploy your web application on HTTP Port (80), allow http port (80) on the firewall first. Run: # ufw allow 80 then run: # streamlit run main.py --server.port 80 Change main.py to your python script file name. To view your deployed web application, visit http://server_ipaddress Troubleshooting If you have encountered some issues or want to learn more, please visit the Streamlit documentation.

Was this answer helpful?
Back

Powered by WHMCompleteSolution