Showing posts with label Data Science. Show all posts
Showing posts with label Data Science. Show all posts

Monday, January 02, 2023

Notes on deploying and troubleshooting a Streamlit app on Azure App Services

 A couple of weeks ago I was playing around with Streamlit and decided to deploy it on Azure a
using Azure App Services using the guidance from Deploying Streamlit Applications with Azure App Services . 

Streamlit is an open-source Python library that allows you to create interactive, data-driven web applications in just a few lines of Python code. It does not require you to have any JavaScript, html or CSS experience.  




The deployment using the steps outlined in the blog post went quite smooth but when I navigated to the website, I was greeted by an exception.

Since I haven't worked with Linux for over 20 years now, I feared to be in for a long and painful experience to get this resolved but it actually turned out to be easier then expected. 

First step, I took was looking at the Application Logs for the Azure Web App. Go to the Azure App Service > Diagnose and solve problems > Application Logs. 

When scrolling through the Application Logs

The exception log "TypeError: Descriptor cannot be created directly. Your  generated code is 
out of data and must be regenerated with protoc > 3.19.0. If you cannot immediately
regenerate your protos, some other possible workarounds are: 1. Downgrade the protobuf package to 3.20.x or lower" actually pointed me to a thread on the Streamlit forums - Issue with Protocol Buffers. After changing requirements.txt  to deploy a newer version of Streamlit (see Configure a Linux Python App for Azure App Service for more details on how the Azure App Service deployment engine automatically runs pip install.) all started working correctly again.

Tuesday, September 20, 2022

Quick tip: updating Anaconda with command prompt

 I recently started getting a popup for updating Anaconda Navigator on my Windows machine and I also received a warning when installing packages using the Anaconda prompt. I first started the update through the user interface but this update completely stalled and I had to do a hard reboot after almost 2 hours (when my patience ran out). Running the update using Anaconda prompt worked without problems - next time I will use this method first. If conda is installed on your machine, you can update it to the most recent version and patches using  conda update -n base -c defaults conda



Thursday, July 16, 2020

How to use secrets in Jupyter Notebooks with python-dotenv

It is not a good idea to embed the the secrets (credentials, keys, etc..) that you need in your Python code directly in your Jupyter Notebooks. You can store these secrets in environment variables but an alternative is using the python-dotenv library. Python-dotenv is a library that reads key-value pairs from  a .env file and adds them to environment variables.

To get started you need to install the latest version of python-dotevn and then you will need to create a .env file in the same folder as your .ipynb files.



Tip: You may not be able to create .env file directly in Windows Explorer - use the command prompt and the echo command to create this file.




You can read a key-value pair in just one line of code after you loaded the extension and the os module which provides functions to interact with the operating system.



Source code is available on https://github.com/jorisp/tradingnotebooks/blob/master/dotenv.ipynb

References: