Everything works fine in my local environment. However, I am getting a locale error: unsupported locale setting error on deploying to Streamlit cloud. I am setting the locale as follows -
Hey,
I’m getting a similar issue when attempting to set the locale on Streamlit cloud.
Steps to produce:
import locale
def format_money(res: int) -> str:
"""
Given some int, convert it to currency
Args:
res (int): Money input as int
Returns:
str: Currency as string
"""
locale.setlocale(locale.LC_ALL, "")
return locale.currency(res, grouping=True)
money = format_money(2)
Expected Result $2.00
Actual Result ValueError: Currency formatting is not possible using the 'C' locale.
The solution according to this StackOverflow post is to use instead:
locale.setlocale(locale.LC_ALL, 'en_CA.UTF-8')
Your code would need to be modified to the following:
import locale
import streamlit as st
def format_money(res: int) -> str:
"""
Given some int, convert it to currency
Args:
res (int): Money input as int
Returns:
str: Currency as string
"""
locale.setlocale(locale.LC_ALL, "en_CA.UTF-8")
return locale.currency(res, grouping=True)
money = format_money(2)
st.write(money)
To get this working on Community Cloud, create a packages.txt file in your repo containing:
locales
locales-all
Then the following code should work:
import locale
import streamlit as st
def format_money(res: int) -> str:
"""
Given some int, convert it to currency
Args:
res (int): Money input as int
Returns:
str: Currency as string
"""
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
return locale.currency(res, grouping=True)
money = format_money(2)
st.write(money)
The packages.txt file contains debian dependencies that will be installed in your app container via apt-get install. Precompiled locale data usually does not exist on fresh systems (new debian containers). We install them via packages.txt: