Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django Gunicorn:找不到应用程序_Python_Django_Gunicorn - Fatal编程技术网

Python Django Gunicorn:找不到应用程序

Python Django Gunicorn:找不到应用程序,python,django,gunicorn,Python,Django,Gunicorn,我首先将django重新安装到Python3.4VirtualEnv中。然后,我尝试按照教程启动gunicorn,在第一次运行时进行测试,但失败了。我有一个完全配置的开发服务器,gunicorn无法在其中运行,这向我显示了相同的错误,即没有名为.wsgi的模块 (test_projectprodenv)djangouser@ff:~$ gunicorn test_project.wsgi:application --bind 162.243.195.141:8001 Exception in w

我首先将django重新安装到Python3.4VirtualEnv中。然后,我尝试按照教程启动gunicorn,在第一次运行时进行测试,但失败了。我有一个完全配置的开发服务器,gunicorn无法在其中运行,这向我显示了相同的错误,即没有名为
.wsgi
的模块

(test_projectprodenv)djangouser@ff:~$ gunicorn test_project.wsgi:application --bind 162.243.195.141:8001
Exception in worker process:
Traceback (most recent call last):
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/arbiter.py", line 502, in spawn_worker
    worker.init_process()
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/workers/base.py", line 114, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/app/base.py", line 66, in wsgi
    self.callable = self.load()
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/util.py", line 356, in import_app
    __import__(module)
ImportError: No module named 'test_project.wsgi'
我启动一个新服务器来测试这个新的Django项目的唯一原因是希望gunicorn能够工作,因为我可能在我的旧开发服务器上配置了一些错误的东西。请记住,这是完全新鲜的。在Django项目文件夹或
settings.py
中,除了配置数据库之外,我什么都没碰过

编辑:添加了文件结构

(test_projectprodenv)djangouser@ff:~$ ls
test_project  test_projectprodenv  

(test_projectprodenv)djangouser@ff:~/test_project$ tree
.
├── test_project
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-34.pyc
│   │   ├── settings.cpython-34.pyc
│   │   ├── urls.cpython-34.pyc
│   │   └── wsgi.cpython-34.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

2 directories, 9 files
正在从测试项目文件夹执行
gunicorn
命令

(test_projectprodenv)djangouser@ff:~$ which gunicorn
/home/djangouser/test_projectprodenv/bin/gunicorn

如果您的应用程序未与Gunicorn一起安装在Python环境中,则必须将其添加到Python路径中,以便Gunicorn可以通过从包所在的位置运行或通过命令行选项指定该位置来查看它

因此,要么从
~/test\u项目启动服务器

~/test_project$ gunicorn test_project.wsgi:application --bind 162.243.195.141:8001
或者使用主目录中的
--pythonpath
选项:

~$ gunicorn test_project.wsgi:application --pythonpath test_project --bind 162.243.195.141:8001

似乎是一个路径问题。你能发布你的目录结构,以及运行上面命令的文件夹吗?@SohanJain是的,对不起,我添加了它。我在virtualenv中安装了gunicorn,因此我在激活virtualenv时执行gunicorn命令。您发布的stacktrace表明您正在从主文件夹运行gunicorn,您需要从/home/djangouser/test运行它_project@JeremyAllen您好,先生,您完全正确。这个问题困扰了我整整一个星期。我终于发布了stackoverflow,你在几分钟内就解决了。上帝保佑你,先生。非常感谢:)。如果你愿意的话,请把它作为一个答案贴出来,这样对将来遇到同样问题的用户会有帮助。太好了。
--pythonpath
选项和您的解释对我帮助很大。谢谢:)