ImportError: No module named ..

Le problème exposé dans ce sujet a été résolu.

Problème résolu ! Il faut rajouter les applications au PYTHONPATH afin que Python puisse y accéder. Par exemple dans le cadre du tuto:

1
2
PYTHONPATH="${PYTHONPATH}:/var/www/"
export PYTHONPATH

Ou via python:

1
2
import sys
sys.path.append("/var/www/")

Vous trouverez plus d'info ici, ici et ici

Bonjour :-) ,

J'essaie de mettre en production un site réalisé via Django mais je n'arrive pas à faire démarrer Gunicorn.

Comme dans le tutoriel Développez votre site web avec le framework Django mon fichier settings.py contient mes applications comme présenté dans le tuto:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'blog',
)

L'architecture de mon projet ressemble à celle du tuto:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
crepes_bretonnes/
        manage.py
        crepes_bretonnes/
                __init__.py
                settings.py
                urls.py
                wsgi.py
        blog/
                __init__.py
                models.py
                tests.py
                views.py

J'utilise cette commande pour lancer gunicorn:

1
2
3
4
5
6
7
 gunicorn wsgi:application \
 --chdir=/var/www/crepes_bretonnes/ \
 --settings=/var/www/settings.py \
 --env DJANGO_SETTINGS_MODULE="settings" \
 --log-level=debug \
 --log-file=/var/log/gunicorn/gunicorn.log \
 -b 127.0.0.1:8000

Et finalement j'obtiens les logs suivant dans /var/log/gunicorn/gunicorn.log

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
[2015-11-22 17:51:19 +0000] [157] [DEBUG] Current configuration:
  proxy_protocol: False
  worker_connections: 1000
  statsd_host: None
  max_requests_jitter: 0
  post_fork: <function post_fork at 0x7f6c2ff47d70>
  pythonpath: None
  enable_stdio_inheritance: False
  worker_class: sync
  ssl_version: 3
  suppress_ragged_eofs: True
  syslog: False
  syslog_facility: user
  when_ready: <function when_ready at 0x7f6c2ff47aa0>
  pre_fork: <function pre_fork at 0x7f6c2ff47c08>
  cert_reqs: 0
  preload_app: False
  keepalive: 2
  accesslog: None
  group: 0
  graceful_timeout: 30
  do_handshake_on_connect: False
  spew: False
  workers: 1
  proc_name: None
  sendfile: True
  pidfile: None
  umask: 0
  on_reload: <function on_reload at 0x7f6c2ff47938>
  pre_exec: <function pre_exec at 0x7f6c2ff4f398>
  worker_tmp_dir: None
  post_worker_init: <function post_worker_init at 0x7f6c2ff47ed8>
  limit_request_fields: 100
  on_exit: <function on_exit at 0x7f6c2ff4fa28>
  config: None
  secure_scheme_headers: {'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https', 'X-FORWARDED-SSL': 'on'}
  proxy_allow_ips: ['127.0.0.1']
  pre_request: <function pre_request at 0x7f6c2ff4f500>
  post_request: <function post_request at 0x7f6c2ff4f5f0>
  user: 0
  forwarded_allow_ips: ['127.0.0.1']
  worker_int: <function worker_int at 0x7f6c2ff4f0c8>
  threads: 1
  max_requests: 0
  limit_request_line: 4094
  access_log_format: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
  certfile: None
  worker_exit: <function worker_exit at 0x7f6c2ff4f758>
  chdir: /var/www/crepes_bretonnes
  paste: None
  default_proc_name: wsgi:application
  errorlog: /var/log/gunicorn/gunicorn.log
  loglevel: debug
  logconfig: None
  syslog_addr: udp://localhost:514
  syslog_prefix: None
  daemon: False
  ciphers: TLSv1
  on_starting: <function on_starting at 0x7f6c2ff477d0>
  worker_abort: <function worker_abort at 0x7f6c2ff4f230>
  bind: ['127.0.0.1:8000']
  raw_env: ['DJANGO_SETTINGS_MODULE=settings']
  reload: False
  check_config: False
  limit_request_field_size: 8190
  nworkers_changed: <function nworkers_changed at 0x7f6c2ff4f8c0>
  timeout: 30
  ca_certs: None
  django_settings: /var/www/crepes_bretonnes/settings.py
  tmp_upload_dir: None
  keyfile: None
  backlog: 2048
  logger_class: gunicorn.glogging.Logger
  statsd_prefix: 
[2015-11-22 17:51:19 +0000] [157] [INFO] Starting gunicorn 19.3.0
[2015-11-22 17:51:19 +0000] [157] [DEBUG] Arbiter booted
[2015-11-22 17:51:19 +0000] [157] [INFO] Listening at: http://127.0.0.1:8000 (157)
[2015-11-22 17:51:19 +0000] [157] [INFO] Using worker: sync
[2015-11-22 17:51:19 +0000] [162] [INFO] Booting worker with pid: 162
[2015-11-22 17:51:19 +0000] [157] [DEBUG] 1 workers
[2015-11-22 17:51:19 +0000] [162] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 118, in init_process
    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 355, in import_app
    __import__(module)
  File "/var/www/crepes_bretonnes/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, 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 86, 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 blog
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 118, in init_process
    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 355, in import_app
    __import__(module)
  File "/var/www/crepes_bretonnes/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, 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 86, 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 blog
[2015-11-22 17:51:19 +0000] [162] [INFO] Worker exiting (pid: 162)
[2015-11-22 17:51:20 +0000] [157] [INFO] Shutting down: Master
[2015-11-22 17:51:20 +0000] [157] [INFO] Reason: Worker failed to boot.

Merci d'avance pour votre aide ! :-)

+0 -0
Connectez-vous pour pouvoir poster un message.
Connexion

Pas encore membre ?

Créez un compte en une minute pour profiter pleinement de toutes les fonctionnalités de Zeste de Savoir. Ici, tout est gratuit et sans publicité.
Créer un compte