You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Streamlit调用streamlit_lottie报错:'module' object is not callable

解决Streamlit中添加Lottie动画出现的TypeError问题

问题原因

你遇到的TypeError: 'module' object is not callable错误,是因为把streamlit_lottie模块本身当成了函数调用。实际上,该模块的核心渲染函数是lottie,需要调用这个函数而非模块本身。

解决方案

两种修正方式任选其一即可:

方式1:直接导入目标函数

修改导入语句,直接导入st_lottie函数:

from streamlit_lottie import st_lottie
import requests

# 你的load_lottieurl函数保持不变
def load_lottieurl(url):
    r = requests.get(url)
    if r.status_code !=200:
        return None
    return r.json()
coding = load_lottieurl("https://assets3.lottiefiles.com/packages/lf20_3rwasyjy.json")

with right_column:
    st_lottie(coding)  # 直接调用导入的函数

方式2:调用模块内的lottie函数

若保留原导入方式,调用时需指定模块内的lottie函数:

import streamlit_lottie as st_lottie
import requests

# 你的load_lottieurl函数保持不变
def load_lottieurl(url):
    r = requests.get(url)
    if r.status_code !=200:
        return None
    return r.json()
coding = load_lottieurl("https://assets3.lottiefiles.com/packages/lf20_3rwasyjy.json")

with right_column:
    st_lottie.lottie(coding)  # 明确调用模块内的lottie函数

说明

两种方式本质都是调用streamlit_lottie模块的lottie核心渲染函数,仅导入和调用的写法不同,都能正常渲染Lottie动画。

内容的提问来源于stack exchange,提问作者MIMI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 15:31:42