Я пытаюсь перенести базу данных SQLite в моем приложении Django на MySQL. Из-за некоторых проблем с MySQL Python Connector я решил перейти на Python 3.6 в дистрибутиве Debian, где я работаю.
После переноса базы данных я попытался запустить приложение, но у меня появилась эта ошибка в файле журнала ошибок apache:
Current thread 0x00007f1488aee780 (most recent call first):
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Я добавил это в свой httpd.conf:
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
LoadModule wsgi_module /usr/local/venvs/myapp/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
#Django
WSGIDaemonProcess django_myapp python-home=/usr/local/venvs/myapp
WSGIProcessGroup django_myapp
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/django/django_myapp/wsgi.py
WSGIPassAuthorization On
Alias /static /var/www/django/static
<Directory /var/www/django/static>
Require all granted
</Directory>
<Directory /var/www/django/django_myapp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Из файла error.log:
Apache/2.4.10 (Debian) mod_wsgi/4.6.5 Python/3.6
Я установил новую версию Python с помощью команды
env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.3
.
Я настроил виртуальную среду и установил весь пакет, необходимый для запуска моего приложения через pip.
Также mod_wsgi
устанавливается через пипс.