简体   繁体   中英

ModuleNotFoundError: No module named 'config'

I know there is a similar question to this:

django-admin startproject results in "ModuleNotFoundError: No module named 'config'"

But the answer does not worked for me.

I have a VPS running Ubuntu (18.04) + Apache (2.4.29).

The applications runs well by this command line:

python3 manage.py runserver 0.0.0.0:8000 --settings=config.settings.production

My Apache conf look like this:

WSGIDaemonProcess myapp python-home=/home/my_repository/ENV

WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}

WSGIScriptAlias / /home/my_repository/config/wsgi.py

<Directory /home/my_repository/>
    Require all granted
</Directory>

I am seeing this error on the Apache.log:

mod_wsgi (pid=32745): Target WSGI script '/home/my_repository/config/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=32745): Exception occurred processing WSGI script '/home/my_repository/config/wsgi.py'.
Traceback (most recent call last):
  File "/home/my_repository/config/wsgi.py", line 39, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python3.6/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 76, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/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 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 'config'

I also confirmed what versions and vars my wsgi.py is configured with:

DJANGO_SETTINGS_MODULE: config.settings.production
Python version: 3.6.9
Django version: 3.0.3

I hope anyone can help me. I am trying to run bootcamp for almost a month now 😞

The problem was the python working directory.

It was pointing to / .

To set the working directory you need to specify the home parameter at the WSGIDaemonProcess .

My apache conf ended up like this:

WSGIDaemonProcess myapp python-home=/home/my_repository/ENV home=/home/my_repository

WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}

WSGIScriptAlias / /home/my_repository/config/wsgi.py

<Directory /home/my_repository/>
    Require all granted
</Directory>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM