Gunicorn无法绑定Django项目,启动报错求助
问题解决:Gunicorn启动时提示找不到Django模块
问题根源
你激活了虚拟环境,但当前运行的是系统全局安装的Gunicorn,它无法访问虚拟环境内的Django依赖包。
解决步骤
确认虚拟环境已激活
确保命令行前缀显示(venv_django_proj),如果没有,执行激活命令:source venv_django_proj/bin/activate在虚拟环境内重新安装Gunicorn
把Gunicorn安装到虚拟环境中,让它能调用环境内的Django:pip install gunicorn验证Gunicorn路径
执行以下命令,确认Gunicorn来自虚拟环境:which gunicorn输出应该类似:
~/django_proj/venv_django_proj/bin/gunicorn,而非系统路径(如/usr/bin/gunicorn)。重新启动Gunicorn
回到包含manage.py的项目根目录(即~/django_proj),执行启动命令:gunicorn django_proj.wsgi
备选方案(无需激活环境)
直接使用虚拟环境内Gunicorn的绝对路径运行:
~/django_proj/venv_django_proj/bin/gunicorn django_proj.wsgi
内容的提问来源于stack exchange,提问作者Sankar Narayanan
相关产品推荐
相关产品推荐

