web-dev-qa-db-ja.com

Djangoプロジェクトフォルダーではないフォルダーからgunicornを実行する方法

プロジェクトをホームフォルダーにgit cloneしました。/home/telessaudeと名付けましょう。したがって、プロジェクトルートは/home/telessaude/telessaude_branch_masterにあります。

Django=プロジェクトのホームフォルダー(/ home/telessaude/telessaude_branch_master)の中にいて、次のようなgunicornコマンドを発行する場合

gunicorn -w 2 -b 0.0.0.0:8000 telessaude.wsgi_dev:application --reload --timeout 900

gunicornが起動し、正常に動作します。ただし...上記の1つのディレクトリ(/ home/telessaude)で同じコマンドを実行しようとすると、次のエラーが発生します。

telessaude@ubuntu:~$ gunicorn -w 2 -b 0.0.0.0:8000 telessaude.wsgi_dev:application --reload --timeout 900
[2017-03-22 16:39:28 +0000] [10405] [INFO] Starting gunicorn 19.6.0
[2017-03-22 16:39:28 +0000] [10405] [INFO] Listening at: http://0.0.0.0:8000 (10405)
[2017-03-22 16:39:28 +0000] [10405] [INFO] Using worker: sync
[2017-03-22 16:39:28 +0000] [10410] [INFO] Booting worker with pid: 10410
[2017-03-22 16:39:28 +0000] [10410] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 357, in import_app
    __import__(module)
ImportError: No module named telessaude.wsgi_dev

私もホームフォルダでgunicornを実行してみました

gunicorn -w 2 -b 0.0.0.0:8000 telessaude_branch_master.telessaude.wsgi_dev:application --reload --timeout 900

そして

gunicorn -w 2 -b 0.0.0.0:8000 /home/telessaude/telessaude_branch_master/telessaude.wsgi_dev:application --reload --timeout 900

しかし、どれもうまくいきませんでした。誰かがこれを修正する方法を教えてもらえますか?スーパーバイザの「コマンド」パラメータとして追加する必要があるため、任意のフォルダからgunicornを実行する必要があります。

私は仮想環境を使用していません。

12
Vini.g.fer

DjangoアプリをPythonパスに追加する必要があります。

最新のgunicornでは、これを試すことができます:

Djangoプロジェクトのルートパスが/usr/local/src/djangoapp/の場合。

settings.pyパスのデフォルトは/usr/local/src/djangoapp/djangoapp/settings.pyです。

gunicorn \
-c /usr/local/src/djangoapp/gunicorn_config.py \
--env Django_SETTINGS_MODULE=djangoapp.settings \
--pythonpath '/usr/local/src/djangoapp' \
djangoapp.wsgi:application
  • -c構成ファイルのパス
  • -envDjangoプロジェクトのsettings.pyのモジュールパス
  • -pythonpathPythonパスにプロジェクトパスを追加 settings.html#pythonpath

--envおよび--pythonpathは必須です。

相対パスも問題ありません!

0
m.kobe