0

i deploy a website (in Django) and i isolate a error from the Apache error_log that correspond to a problem of loading import.

But i dont know how to solve it !!!

wsgi.py

"""
WSGI config for MYSITE project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""

import os
import sys

from django.core.wsgi import get_wsgi_application

path = 'PATHTOMYSITE'

if path not in sys.path:
   sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MYSITE.settings")

application = get_wsgi_application()

Running Python in sudo for test

sudo /MYVIRTUALENV/bin/python3.6

wsgi.py lines code....

no error

Running Python without sudo mod for test

sudo /MYVIRTUALENV/bin/python3.6

wsgi.py lines code....

And at the line :

application = get_wsgi_application()

I have this error :

  File "<stdin>", line 1, in <module>
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'MYSITE'

For me the problem is here :

   File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)

But i really dont know how to solve it.

Django = 2.0.4 Python = 3.6

Thank you in advance for those who will help me in this problem =)

EDIT 1

Here my pythonpath

sudo /MYVIRTUALENV/bin/python3.6
Python 3.6.5 (default, Apr 10 2018, 17:08:37) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/MYVIRTUALENV/lib64/python3.6/site-packages', '/MYVIRTUALENV/lib/python3.6/site-packages']

EDIT 2

I discover that :

when i run manage.py, i have no error with this...

sudo MYVIRTUALENV/bin/python3.6 MYSITE/manage.py runserver

but i have an different error if run only the wsgi.py file with a print on the settings:

sudo MYVIRTUALENV/bin/python3.6 MYSITE/Site_CNR/wsgi.py
Traceback (most recent call last):
  File "MYSITE/MYSITE/wsgi.py", line 23, in <module>
    application = get_wsgi_application()
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/__init__.py", line 22, in setup
    print(settings)
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/utils/functional.py", line 215, in inner
    self._setup()
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/MYVIRTUALENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 107, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in     import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/MYSITEPATH/MYSITE/__init__.py", line 5, in <module>
    from .celery import app as celery_app
  File "/MYSITEPATH/MYSITE/celery.py", line 3, in <module>
    from celery import Celery
  File "/MYSITEPATH/MYSITE/celery.py", line 3, in <module>
    from celery import Celery
ImportError: cannot import name 'Celery'

Maybe the problem is a permission problem but i dont see where it can be.

EDIT 3

I solved the problem of the EDIT 2 error messages with the solution to rename the file '/MYSITEPATH/MYSITE/celery.py' explained here Django, ImportError: cannot import name Celery, possible circular import?

EDIT 4

I still have the problem and the same error described in my part Running Python without sudo mod for test but not anymore with this command line application = get_wsgi_application() ... (yeah =))

now just only in the apache error_log file

[Mon Jun 18 10:17:16.032108 2018] [mpm_prefork:notice] [pid 46311] AH00170: caught SIGWINCH, shutting down gracefully
[Mon Jun 18 10:17:17.136320 2018] [core:notice] [pid 46895] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Mon Jun 18 10:17:17.136995 2018] [suexec:notice] [pid 46895] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Jun 18 10:17:17.146641 2018] [auth_digest:notice] [pid 46895] AH01757: generating secret for digest authentication ...
[Mon Jun 18 10:17:17.147326 2018] [lbmethod_heartbeat:notice] [pid 46895] AH02282: No slotmem from mod_heartmonitor
[Mon Jun 18 10:17:17.151899 2018] [mpm_prefork:notice] [pid 46895] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/4.6.4 Python/3.6 configured -- resuming normal operations
[Mon Jun 18 10:17:17.151924 2018] [core:notice] [pid 46895] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Mon Jun 18 10:17:31.564233 2018] [wsgi:error] [pid 46896] Site_CNR.settings
[Mon Jun 18 10:17:31.564275 2018] [wsgi:error] [pid 46896] /usr/lib64/python3.6/importlib/__init__.py
[Mon Jun 18 10:17:31.564463 2018] [wsgi:error] [pid 46896] [remote MYIP] mod_wsgi (pid=46896): Failed to exec Python script file '/PATHTOMYSITE/MYSITE/MYSITE/wsgi.py'.
[Mon Jun 18 10:17:31.564497 2018] [wsgi:error] [pid 46896] [remote MYIP] mod_wsgi (pid=46896): Exception occurred processing WSGI script '/PATHTOMYSITE/MYSITE/MYSITE/wsgi.py'.
[Mon Jun 18 10:17:31.565032 2018] [wsgi:error] [pid 46896] [remote MYIP] Traceback (most recent call last):
[Mon Jun 18 10:17:31.565079 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "/PATHTOMYSITE/MYSITE/MYSITE/wsgi.py", line 21, in <module>
[Mon Jun 18 10:17:31.565083 2018] [wsgi:error] [pid 46896] [remote MYIP]     application = get_wsgi_application()
[Mon Jun 18 10:17:31.565089 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "/PATHTOMYVENV/lib64/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Mon Jun 18 10:17:31.565092 2018] [wsgi:error] [pid 46896] [remote MYIP]     django.setup(set_prefix=False)
[Mon Jun 18 10:17:31.565099 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "/PATHTOMYVENV/lib64/python3.6/site-packages/django/__init__.py", line 19, in setup
[Mon Jun 18 10:17:31.565102 2018] [wsgi:error] [pid 46896] [remote MYIP]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Jun 18 10:17:31.565107 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "/PATHTOMYVENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
[Mon Jun 18 10:17:31.565110 2018] [wsgi:error] [pid 46896] [remote MYIP]     self._setup(name)
[Mon Jun 18 10:17:31.565115 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "/PATHTOMYVENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
[Mon Jun 18 10:17:31.565118 2018] [wsgi:error] [pid 46896] [remote MYIP]     self._wrapped = Settings(settings_module)
[Mon Jun 18 10:17:31.565123 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "/PATHTOMYVENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 109, in __init__
[Mon Jun 18 10:17:31.565126 2018] [wsgi:error] [pid 46896] [remote MYIP]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Jun 18 10:17:31.565131 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
[Mon Jun 18 10:17:31.565133 2018] [wsgi:error] [pid 46896] [remote MYIP]     return _bootstrap._gcd_import(name[level:], package, level)
[Mon Jun 18 10:17:31.565138 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Mon Jun 18 10:17:31.565143 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Mon Jun 18 10:17:31.565157 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
[Mon Jun 18 10:17:31.565162 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Mon Jun 18 10:17:31.565167 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Mon Jun 18 10:17:31.565172 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Mon Jun 18 10:17:31.565176 2018] [wsgi:error] [pid 46896] [remote MYIP]   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Mon Jun 18 10:17:31.565190 2018] [wsgi:error] [pid 46896] [remote MYIP] ModuleNotFoundError: No module named 'MYSITE'
DalinDad
  • 103
  • 1
  • 14
  • Looks to me that you defined in `INSTALLED_APPS` a `'MYSITE'`, and that can not be loaded correctly, or the Python path is set the wrong way. – Willem Van Onsem Jun 14 '18 at 09:17
  • @WillemVanOnsem I edited my post with python path settings. What can be the problem with `INSTALLED_APPS` ? – DalinDad Jun 14 '18 at 09:23

0 Answers0