@Matthew06

Как исправить ошибку «ModuleNotFoundError: No module named 'pymysql'» при подключении проекта django к apache?

У меня есть проект на django и я пытаюсь связать его с apache. Сразу скажу, что использую не виртуальный, а системный python. Файл 000-default.conf:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        alias /static /home/belyash/PycharmProjects/prohect_iem/static

        <Directory /home/belyash/PycharmProjects/prohect_iem/static>
                Require all granted
        </Directory>

        <Directory /home/belyash/PycharmProjects>
                Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /home/belyash/PycharmProjects/prohect_iem/base/>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        <Directory />
                Require all granted
        </Directory>

        WSGIDaemonProcess prohect_iem python-path=/home/belyash/PycharmProjects/prohect_iem 
        WSGIProcessGroup prohect_iem
        WSGIScriptAlias / /home/belyash/PycharmProjects/prohect_iem/base/wsgi.py


</VirtualHost>


После перезапуска сервиса apache и переходе на сайт в логах следующая ошибка :

[Fri Aug 09 11:36:12.643849 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610] mod_wsgi (pid=28597): Failed to exec Python script file '/home/belyash/PycharmProjects/prohect_iem/base/wsgi.py'.
[Fri Aug 09 11:36:12.643967 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610] mod_wsgi (pid=28597): Exception occurred processing WSGI script '/home/belyash/PycharmProjects/prohect_iem/base/wsgi.py'.
[Fri Aug 09 11:36:12.644282 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610] Traceback (most recent call last):
[Fri Aug 09 11:36:12.644392 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "/home/belyash/PycharmProjects/prohect_iem/base/wsgi.py", line 16, in <module>
[Fri Aug 09 11:36:12.644430 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]     application = get_wsgi_application()
[Fri Aug 09 11:36:12.644442 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "/usr/local/lib/python3.10/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Fri Aug 09 11:36:12.644450 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]     django.setup(set_prefix=False)
[Fri Aug 09 11:36:12.644463 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "/usr/local/lib/python3.10/dist-packages/django/__init__.py", line 19, in setup
[Fri Aug 09 11:36:12.644473 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Fri Aug 09 11:36:12.644485 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "/usr/local/lib/python3.10/dist-packages/django/conf/__init__.py", line 89, in __getattr__
[Fri Aug 09 11:36:12.644495 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]     self._setup(name)
[Fri Aug 09 11:36:12.644507 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "/usr/local/lib/python3.10/dist-packages/django/conf/__init__.py", line 76, in _setup
[Fri Aug 09 11:36:12.644516 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]     self._wrapped = Settings(settings_module)
[Fri Aug 09 11:36:12.644529 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "/usr/local/lib/python3.10/dist-packages/django/conf/__init__.py", line 190, in __init__
[Fri Aug 09 11:36:12.644540 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Fri Aug 09 11:36:12.644552 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
[Fri Aug 09 11:36:12.644561 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]     return _bootstrap._gcd_import(name[level:], package, level)
[Fri Aug 09 11:36:12.644574 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[Fri Aug 09 11:36:12.644587 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[Fri Aug 09 11:36:12.644599 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
[Fri Aug 09 11:36:12.644610 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[Fri Aug 09 11:36:12.644623 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[Fri Aug 09 11:36:12.644636 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[Fri Aug 09 11:36:12.644648 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
[Fri Aug 09 11:36:12.644660 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
[Fri Aug 09 11:36:12.644672 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
[Fri Aug 09 11:36:12.644684 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[Fri Aug 09 11:36:12.644698 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]   File "/home/belyash/PycharmProjects/prohect_iem/base/__init__.py", line 1, in <module>
[Fri Aug 09 11:36:12.644723 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610]     import pymysql
[Fri Aug 09 11:36:12.644751 2024] [wsgi:error] [pid 28597:tid 126717864638016] [remote ::1:36610] ModuleNotFoundError: No module named 'pymysql'


Пишет, что проблема в init.py

import pymysql

pymysql.install_as_MySQLdb()

Если запускать просто проект django (через manage.py runserver), то все работает.
  • Вопрос задан
  • 89 просмотров
Пригласить эксперта
Ответы на вопрос 1
Wispik
@Wispik
pip install pymysql
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы