ModuleNotFoundError: No module named ‘gunicorn.app‘; ‘gunicorn‘ is not a package

Posted xiejunna

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ModuleNotFoundError: No module named ‘gunicorn.app‘; ‘gunicorn‘ is not a package相关的知识,希望对你有一定的参考价值。

问题描述

gunicorn 启动python项目时,抛异常:ModuleNotFoundError: No module named 'gunicorn.app'; 'gunicorn' is not a package
具体异常如下:

Traceback (most recent call last):
  File "/home/dev/anaconda3/envs/torch/bin/gunicorn", line 5, in <module>
    from gunicorn.app.wsgiapp import run
ModuleNotFoundError: No module named 'gunicorn.app'; 'gunicorn' is not a package

问题分析

项目启动时,找不到gunicorn.app安装包 vi gunicorn,先查看下安装包的查找路径,添加了print输出


查看输出sys.path发现项目依赖环境在项目的后面,找不到依赖包也是正常

解决办法

查看抛异常语句中,找到报错的文件,按报错的文件位置cd进去,vi命令打开报错文件,把依赖环境路径添加到要导包报错的前面,问题得以解决!这个配置路径要根据自己环境安装的实际路径来配置 sys.path[0]='/home/dev/anaconda3/envs/torch/lib/python3.6/site-packages'

Traceback (most recent call last):
  File "/home/dev/anaconda3/envs/torch/bin/gunicorn", line 5, in <module>
    from gunicorn.app.wsgiapp import run
ModuleNotFoundError: No module named 'gunicorn.app'; 'gunicorn' is not a package


#!/home/dev/anaconda3/envs/torch/bin/python
# -*- coding: utf-8 -*-
import re
import sys
print(sys.path)
sys.path[0]='/home/dev/anaconda3/envs/torch/lib/python3.6/site-packages'
print(sys.path)
from gunicorn.app.wsgiapp import run
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])
    sys.exit(run())

以上是关于ModuleNotFoundError: No module named ‘gunicorn.app‘; ‘gunicorn‘ is not a package的主要内容,如果未能解决你的问题,请参考以下文章

ModuleNotFoundError: No module named 'gdbm'

Python:ModuleNotFoundError: No module named 'windows'

PySpark 自定义 UDF ModuleNotFoundError: No module named

用Java调用.py程序出现ModuleNotFoundError: No module named 'java'

ModuleNotFoundError: No module named 'jupyter_contrib_nbextensions' .ipynb文件转换.py文件时遇到错误(示例

ModuleNotFoundError: No module named 'jupyter_contrib_nbextensions' .ipynb文件转换.py文件时遇到错误(示例