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

Python3虚拟环境下用mod_wsgi部署Apache Superset配置错误求助

Apache Superset + mod_wsgi 配置修正方案

问题根源

错误提示的RuntimeError: Working outside of application context,是因为直接导入superset.app未完成应用的初始化流程,Superset需要通过官方提供的create_app()方法生成正确的WSGI应用实例,而非直接引用未初始化的app对象。

修正后的superset.wsgi配置

import sys
import site

# 确保虚拟环境的site-packages被正确识别
site.addsitedir('/var/www/superset/lib/python3.8/site-packages')
sys.path.insert(0, '/var/www/superset')

# 正确初始化Superset应用
from superset.app import create_app
application = create_app()

修正后的superset.conf配置

<VirtualHost *:80>
    # 指定虚拟环境根目录,确保mod_wsgi使用正确的Python解释器
    WSGIDaemonProcess superset python-home=/var/www/superset threads=5
    WSGIScriptAlias / /var/www/superset/superset.wsgi

    WSGIProcessGroup superset
    WSGIApplicationGroup %{GLOBAL}

    # 限制目录权限到superset应用目录,更安全
    <Directory /var/www/superset/>
        Options FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    # 可选:设置静态文件服务(路径需匹配虚拟环境中Superset静态文件位置)
    Alias /static /var/www/superset/lib/python3.8/site-packages/superset/static
    <Directory /var/www/superset/lib/python3.8/site-packages/superset/static/>
        Require all granted
    </Directory>
</VirtualHost>

额外注意事项

  • 确保Apache运行用户(通常为www-data)对/var/www/superset目录有读写权限,尤其是缓存、日志等子目录
  • 重启Apache服务生效:sudo systemctl restart apache2
  • 确认mod_wsgi编译使用的Python版本与虚拟环境版本一致,避免依赖不兼容问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 03:40:20