gunicorn ImportError:没有名为django_jalali的模块

时间:2018-05-13 04:28:52

标签: django python-3.x gunicorn

我正在使用djangonginxgunicorn运行项目,该项目在本地计算机上正常运行。当我将项目移动到服务器并安装所有内容时,我使用python3 manage.py runserver测试了项目,它运行正常。

但是当我尝试使用gunicorn运行它时,我遇到了这个错误

  

ImportError:没有名为django_jalali的模块

完整的gunicorn命令:

gunicorn iteachyou.wsgi:application --bind 127.0.0.1:8003

我已经安装了这个软件包,但实际上没有问题。

这个问题here有一个几乎相似的问题,但它与wsgi有关。我觉得我有点奇怪。

这里是完整的追溯:

[2018-05-13 00:18:34 +0000] [10893] [INFO] Starting gunicorn 19.6.0
[2018-05-13 00:18:34 +0000] [10893] [INFO] Listening at: http://127.0.0.1:8003 (10893)
[2018-05-13 00:18:34 +0000] [10893] [INFO] Using worker: sync
[2018-05-13 00:18:34 +0000] [10897] [INFO] Booting worker with pid: 10897
[2018-05-13 08:48:34 +0000] [10897] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 384, in import_app
    __import__(module)
  File "/var/www/html/iteachyou/iteachyou/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 94, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named django_jalali
[2018-05-13 08:48:34 +0000] [10897] [INFO] Worker exiting (pid: 10897)
[2018-05-13 00:18:34 +0000] [10893] [INFO] Shutting down: Master
[2018-05-13 00:18:34 +0000] [10893] [INFO] Reason: Worker failed to boot.

如果需要,请参阅我安装pip3 install django-jalali时发生的事情:

Collecting django_jalali
  Downloading https://files.pythonhosted.org/packages/a4/91/8d4a89be62d22fcb3a1b7c4c953e532e5f519e66cfec2aadbfd030efb413/django-jalali-3.0.2.tar.gz (200kB)
    100% |████████████████████████████████| 204kB 1.2MB/s
Collecting django>=2.0 (from django_jalali)
  Downloading https://files.pythonhosted.org/packages/23/91/2245462e57798e9251de87c88b2b8f996d10ddcb68206a8a020561ef7bd3/Django-2.0.5-py3-none-any.whl (7.1MB)
    100% |████████████████████████████████| 7.1MB 125kB/s
Collecting jdatetime>=2.0 (from django_jalali)
  Downloading https://files.pythonhosted.org/packages/97/86/51bb0861c702f790abee2894b30d22aa92375523ba8eef165f65066bfb33/jdatetime-2.0.0.tar.gz
Collecting pytz (from django>=2.0->django_jalali)
  Downloading https://files.pythonhosted.org/packages/dc/83/15f7833b70d3e067ca91467ca245bae0f6fe56ddc7451aa0dc5606b120f2/pytz-2018.4-py2.py3-none-any.whl (510kB)
    100% |████████████████████████████████| 512kB 1.5MB/s
Building wheels for collected packages: django-jalali, jdatetime
  Running setup.py bdist_wheel for django-jalali ... done
  Stored in directory: /root/.cache/pip/wheels/64/5a/7b/239e6e9f55125ebdb1795e7ad5be78fe3a3d8a66156a744ee2
  Running setup.py bdist_wheel for jdatetime ... done
  Stored in directory: /root/.cache/pip/wheels/d6/74/93/28caed166abb6bd4194f1802570987c994f6655bb828242c0e
Successfully built django-jalali jdatetime
Installing collected packages: pytz, django, jdatetime, django-jalali
Successfully installed django-2.0.5 django-jalali-3.0.2 jdatetime-2.0.0 pytz-2018.4

更新

我已经说明gunicorn正在使用python2.7

我尝试卸载然后重新安装。但它仍在使用python2.7

如何使用python3代替?

更新2

我尝试卸载django 2然后使用gunicorn并安装新鲜的所有内容。但是gunicorn仍然使用python2.7。

1 个答案:

答案 0 :(得分:0)

最后,我通过安装gunicorn from source来解决问题。

pip3 install git+https://github.com/benoitc/gunicorn.git

现在gunicorn正在使用python3